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

Work on import module

parent 9f419a7d
No related branches found
No related tags found
No related merge requests found
<?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++;
......
This diff is collapsed.
......@@ -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);
......
......@@ -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');
}
......
......@@ -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
......@@ -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>.
......@@ -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
......@@ -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>.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment