diff --git a/htdocs/exports/export.class.php b/htdocs/exports/export.class.php index 5ca179d4834..b5b327238f4 100644 --- a/htdocs/exports/export.class.php +++ b/htdocs/exports/export.class.php @@ -62,7 +62,7 @@ class Export /** * \brief Load an exportable dataset * \param user Object user making export - * \param filter Code export pour charger un lot de donnees particulier + * \param filter Load a particular dataset only */ function load_arrays($user,$filter='') { diff --git a/htdocs/imports/emptyexample.php b/htdocs/imports/emptyexample.php index 316fbb0e665..a9189c32753 100644 --- a/htdocs/imports/emptyexample.php +++ b/htdocs/imports/emptyexample.php @@ -1,6 +1,5 @@ - * Copyright (C) 2005-2007 Regis Houssin +/* 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 @@ -18,576 +17,75 @@ */ /** - * \file htdocs/imports/emptyexamples.php + * \file htdocs/imports/emptyexample.php * \ingroup import - * \brief Show examples of import file + * \brief Show example of import file * \version $Id$ */ -require_once("./pre.inc.php"); -require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php"); -require_once(DOL_DOCUMENT_ROOT."/html.formother.class.php"); +// This is to make Dolibarr working with Plesk +set_include_path($_SERVER['DOCUMENT_ROOT'].'/htdocs'); + +$datatoimport=isset($_GET["datatoimport"])? $_GET["datatoimport"] : (isset($_POST["datatoimport"])?$_POST["datatoimport"]:''); +$format=isset($_GET["format"])? $_GET["format"] : (isset($_POST["format"])?$_POST["format"]:''); + +require("../master.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); require_once(DOL_DOCUMENT_ROOT."/imports/import.class.php"); require_once(DOL_DOCUMENT_ROOT.'/includes/modules/import/modules_import.php'); -$langs->load("exports"); +// C'est un wrapper, donc header vierge +function llxHeader() { print 'Export agenda cal'; } +function llxFooter() { print ''; } + +// Check exportkey +if (empty($datatoimport)) +{ + $user->getrights(); + + llxHeader(); + print '
Bad value for datatoimport.
'; + llxFooter('$Date$ - $Revision$'); + exit; +} -if (! $user->societe_id == 0) -accessforbidden(); - -$array_match_file_to_database=isset($_SESSION["dol_array_match_file_to_database"])?$_SESSION["dol_array_match_file_to_database"]:array(); -$datatoimport=isset($_GET["datatoimport"])? $_GET["datatoimport"] : (isset($_POST["datatoimport"])?$_POST["datatoimport"]:''); -$action=isset($_GET["action"]) ? $_GET["action"] : (isset($_POST["action"])?$_POST["action"]:''); -$step=isset($_GET["step"])? $_GET["step"] : (isset($_POST["step"])?$_POST["step"]:1); -$import_name=isset($_POST["import_name"])? $_POST["import_name"] : ''; -$hexa=isset($_POST["hexa"])? $_POST["hexa"] : ''; -$importmodelid=isset($_POST["importmodelid"])? $_POST["importmodelid"] : ''; +$filename=$langs->trans("ExampleOfImportFile").'_'.$datatoimport.'.'.$format; $objimport=new Import($db); $objimport->load_arrays($user,$datatoimport); - -$objmodelimport=new ModeleImports(); -$html = new Form($db); -$htmlother = new FormOther($db); -$formfile = new FormFile($db); -$sqlusedforimport=''; - - -/* - * Actions - */ - -$objmodelimport=new ModeleImports(); - - - // Load source fields in input file - $fieldssource=array( - 1=>array('name'=>'aa','example1'=>'val1','example2'=>'val2'), - 2=>array('name'=>'bb','example1'=>'valb1','example2'=>'valb2') - ); - - // Load targets fields in database - $fieldstarget=$objimport->array_import_fields[0]; - - $maxpos=max(sizeof($fieldssource),sizeof($fieldstarget)); - - if (sizeof($array_match_file_to_database) == 0) - { - // This is first input in screen, we need to define the $array_match_file_to_database array - $pos=1; - while ($pos <= sizeof($fieldssource)) - { - if (sizeof($fieldssource) > 1 && $pos <= sizeof($fieldssource)) - { - $posbis=1; - foreach($fieldstarget as $key => $val) - { - if ($posbis < $pos) - { - $posbis++; - continue; - } - // We found the key of targets that is at position pos - $array_match_file_to_database[$pos]=$key; - break; - } - } - $pos++; - } - // Save the match array in session. We now will use the array in session. - $_SESSION["dol_array_match_file_to_database"]=$array_match_file_to_database; - } - - // Now $array_match_file_to_database contains fieldnb(1,2,3...)=>fielddatabase(key in $array_match_file_to_database) - - - llxHeader('',$langs->trans("NewImport"),'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones'); - - $param='step=3&datatoimport='.$datatoimport.'&filetoimport='.urlencode($_GET["filetoimport"]); - - $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?'.$param; - $head[$h][1] = $langs->trans("Step")." 3"; - $hselected=$h; - $h++; - - dol_fiche_head($head, $hselected, $langs->trans("NewImport")); - - print ''; - - // Module - print ''; - print ''; - - // Lot de donnees a importer - print ''; - print ''; - - // Nbre champs importes - 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 '
'.$langs->trans("FileToImport").''.$_GET["filetoimport"].'
'; - print '
'; - - - // Combo list of import models - print '
'; - print ''; - print ''; - print ''; - print ''; - print '
'; - print $langs->trans("SelectImportFields",img_picto('','uparrow','')).' '; - $htmlother->select_import_model($importmodelid,'importmodelid',$datatoimport,1); - print ''; - print '
'; - print '
'; - - // Title of array with fields - print ''; - print ''; - print ''; - print ''; - print ''; - - print ''; - - // List of not imported fields - print ''; - - print ''; - print ''; - - print '
'.$langs->trans("FieldsInSourceFile").''.$langs->trans("FieldsInTargetDatabase").'
'; - - //var_dump($array_match_file_to_database); - $pos=1; - - print "\n\n"; - print '
'."\n"; - - // List of source fields -// print ''; - $var=true; - while ($pos <= $maxpos) - { - $var=!$var; - -// print "'; -// print ''; - - show_elem($fieldssource,$pos,$var,$keyfound); - - // Arrows -// print ''; - -// print ''; - -// print ''; - - $pos++; - - if ($pos > sizeof($fieldstarget)) break; - } - - // print '
'; - // Get name of database field at position $pos into $namefield - $namefield=''; - $posbis=1; - foreach($fieldstarget as $key => $val) - { - if ($posbis < $pos) - { - $posbis++; - continue; - } - // We found the key of targets that is at position pos - $namefield=$key; - break; - } - // Now we check if there is a file field linked to this $namefield database field - $keyfound=''; - foreach($fieldssource as $key => $val) - { - if (! empty($array_match_file_to_database[$key]) && $array_match_file_to_database[$key] == $namefield) - { -// print $langs->trans("Field").' '.$key.': '; -// print $fieldssource[$key]['name'].' ('.$fieldssource[$key]['example1'].')'; - $keyfound=$key; - break; - } - } -// print ' '; - if (sizeof($fieldssource) > 1 && $pos <= sizeof($fieldssource)) - { -// if ($pos < $maxpos) print ''.img_down().''; -// if ($pos > 1) print ''.img_up().''; - } -// print ' '; -// if (sizeof($fieldssource) > 1 && $pos <= sizeof($fieldssource)) print ' -> '; -// print '
'; - - print "
\n"; - print "\n"; - - - print '
'; - - // List of targets fields - $i = 0; - $var=true; - print ''; - foreach($fieldstarget as $code=>$label) - { - $var=!$var; - print ''; - - $i++; - - $entity=$objimport->array_import_entities[0][$code]; - $entityicon=$entitytoicon[$entity]?$entitytoicon[$entity]:$entity; - $entitylang=$entitytolang[$entity]?$entitytolang[$entity]:$entity; - - print ''; - print ''; - - print ''; - $save_select.=$bit; - } - print '
'.img_object('',$entityicon).' '.$langs->trans($entitylang).''.$langs->trans($label).' ('.$code.')
'; - - print '
'.$langs->trans("NotImportedFields").'
'; - - print "\n\n"; - print '\n"; - print "\n"; - - print ''; - // Print empty cells - show_elem('','',$var,'none'); - print '
'; - - print ''; - - - if ($conf->use_javascript_ajax) - { - print "\n"; - print ''."\n"; - } - - - if ($mesg) print $mesg; - - /* - * Barre d'action - */ - print '
'; - - if (sizeof($array_match_file_to_database)) - { - print ''.$langs->trans("NextStep").''; - } - - print '
'; - - - // Area for profils import - if (sizeof($array_match_file_to_database)) - { - print '
'; - print $langs->trans("SaveImportModel"); - - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - - print ''; - print ''; - print ''; - print ''; - print ''; - $var=false; - print ''; - print ''; - - // List of existing import profils - $sql = "SELECT rowid, label"; - $sql.= " FROM ".MAIN_DB_PREFIX."import_model"; - $sql.= " WHERE type = '".$datatoimport."'"; - $sql.= " ORDER BY rowid"; - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; - $var=false; - while ($i < $num) - { - $var=!$var; - $obj = $db->fetch_object($resql); - print ''; - $i++; - } - } - else { - dol_print_error($db); - } - - print '
'.$langs->trans("ImportModelName").' 
'; - print ''; - print '
'; - print $obj->label; - print ''; - print 'rowid.'">'; - print img_delete(); - print ''; - print '
'; - print '
'; - } - -} - -if ($step == 4 && $datatoimport) +// Load arrays from descriptor module +$entity=$objimport->array_import_entities[0][$code]; +$entityicon=$entitytoicon[$entity]?$entitytoicon[$entity]:$entity; +$entitylang=$entitytolang[$entity]?$entitytolang[$entity]:$entity; +$fieldstarget=$objimport->array_import_fields[0]; +$valuestarget=$objimport->array_import_examplevalues[0]; + +$attachment = true; +if (isset($_GET["attachment"])) $attachment=$_GET["attachment"]; +//$attachment = false; +$contenttype=dol_mimetype($format); +if (isset($_GET["contenttype"])) $contenttype=$_GET["contenttype"]; +//$contenttype='text/plain'; +$outputencoding='UTF-8'; +//$contenttype='ISO-8859-1'; + +if ($contenttype) header('Content-Type: '.$contenttype.($outputencoding?'; charset='.$outputencoding:'')); +if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"'); + + +// List of targets fields +$headerlinefields=array(); +$contentlinevalues=array(); +$i = 0; +foreach($fieldstarget as $code=>$label) { - asort($array_match_file_to_database); - - 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][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&datatoimport='.$datatoimport; - $head[$h][1] = $langs->trans("Step")." 3"; - $h++; - - $head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=4&datatoimport='.$datatoimport; - $head[$h][1] = $langs->trans("Step")." 4"; - $hselected=$h; - $h++; - - dol_fiche_head($head, $hselected, $langs->trans("NewImport")); - - print ''; - - // Module - print ''; - print ''; - - // Lot de donnees a importer - print ''; - print ''; - - // Nbre champs importes - print ''; - $list=''; - foreach($array_match_file_to_database as $code=>$label) - { - $list.=($list?',':''); - $list.=$langs->trans($objimport->array_import_fields[0][$code]); - } - 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 '
'.$langs->trans("ImportedFields").''.$list.'
'; - print '
'; - - print $langs->trans("NowClickToGenerateToBuildImportFile").'
'; - - // Liste des formats d'imports disponibles - $var=true; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - $liste=$objmodelimport->liste_modeles($db); - foreach($liste as $key) - { - $var=!$var; - print ''; - print ''; - print ''; - } - print '
'.$langs->trans("AvailableFormats").''.$langs->trans("LibraryUsed").''.$langs->trans("LibraryVersion").'
'.img_picto_common($key,$objmodelimport->getPicto($key)).''.$objmodelimport->getDriverLabel($key).''.$objmodelimport->getLibLabel($key).''.$objmodelimport->getLibVersion($key).'
'; - - print ''; - - print ''; - if ($mesg) - { - print ''; - } - if ($sqlusedforimport && $user->admin) - { - print ''; - } - print '
'; - print $mesg; - print '
'; - print info_admin($langs->trans("SQLUsedForImport").':
'.$sqlusedforimport); - print '
'; - - print ''; - print '
'; - - if (! is_dir($conf->import->dir_temp)) create_exdir($conf->import->dir_temp); - - // Affiche liste des documents - // NB: La fonction show_documents rescanne les modules qd genallowed=1 - $formfile->show_documents('import','',$conf->import->dir_temp.'/'.$user->id,$_SERVER["PHP_SELF"].'?step=4&datatoimport='.$datatoimport,$liste,1,(! empty($_POST['model'])?$_POST['model']:'csv'),'',1); - - print ' 
'; - - // If external library PHPEXCELREADER is available - // and defined by PHPEXCELREADER constant. - if (file_exists(PHPEXCELREADER.'excelreader.php')) - { - // Test d'affichage du tableau excel et csv - //print '
'; - //require_once(DOL_DOCUMENT_ROOT.'/lib/viewfiles.lib.php'); - //viewExcelFileContent($conf->import->dir_temp.'/1/import_member_1.xls',5,3); - //viewCsvFileContent($conf->import->dir_temp.'/1/import_member_1.csv',5); - //print '
'; - } -} - - -print '
'; - - -$db->close(); - -llxFooter('$Date$ - $Revision$'); - - -/* - * Function to put the movable box of a source field - */ -function show_elem($fieldssource,$pos,$var,$key) -{ - global $langs,$bc; - - print "\n\n\n"; - print '
'."\n"; - - print ''."\n"; - print ''; - if (empty($key)) - { - print ''; - print ''; - } - elseif ($key == 'none') - { - print ''; - print ''; - } - else - { - //print ''; - print ''; - print ''; - } - print ''; - - print "
'; - print img_picto($langs->trans("MoveBox",$pos),'uparrow','class="boxhandle" style="cursor:move;"'); - print ''; - print $langs->trans("NoFields"); - print ''; - print ' '; - print ''; - print ' '; - print ''.img_file('','').''; - // The image must have the class 'boxhandle' beause it's value used in DOM draggable objects to define the area used to catch the full object - print img_picto($langs->trans("MoveBox",$pos),'uparrow','class="boxhandle" style="cursor:move;"'); - print ''; - print $langs->trans("Field").' '.$key.': '; - print ''.$fieldssource[$key]['name'].' ('.$fieldssource[$key]['example1'].')'; - print '
\n"; - - print "
\n"; - print "\n\n"; + $headerlinefields[]=$fieldstarget[$code].' ('.$code.')'; + $contentlinevalues[]=$valuestarget[$code]; } +//var_dump($headerlinefields); +//var_dump($contentlinevalues); +print $objimport->build_example_file($user,$format,$headerlinefields,$contentlinevalues); ?> diff --git a/htdocs/imports/import.class.php b/htdocs/imports/import.class.php index 4bae0ea4846..3e1367e1972 100644 --- a/htdocs/imports/import.class.php +++ b/htdocs/imports/import.class.php @@ -40,16 +40,16 @@ class Import } - /** - * \brief Load an importable dataset - * \param user Object user making export - * \param filter Code export pour charger un lot de donnees particulier - */ - function load_arrays($user,$filter='') - { - global $langs,$conf; + /** + * \brief Load description of an importable dataset + * \param user Object user making import + * \param filter Load a particular dataset only + */ + function load_arrays($user,$filter='') + { + global $langs,$conf; - dol_syslog("Import::load_arrays user=".$user->id." filter=".$filter); + dol_syslog("Import::load_arrays user=".$user->id." filter=".$filter); //$dir=DOL_DOCUMENT_ROOT."/includes/modules"; foreach($conf->file->dol_document_root as $dirroot) @@ -60,199 +60,138 @@ class Import $handle=@opendir($dir); if ($handle) { - // Recherche des exports disponibles - $var=True; - $i=0; - while (($file = readdir($handle))!==false) - { - if (eregi("^(mod.*)\.class\.php",$file,$reg)) - { - $modulename=$reg[1]; + // Recherche des exports disponibles + $var=True; + $i=0; + while (($file = readdir($handle))!==false) + { + if (eregi("^(mod.*)\.class\.php",$file,$reg)) + { + $modulename=$reg[1]; - // Defined if module is enabled - $enabled=true; - $part=strtolower(eregi_replace('^mod','',$modulename)); + // Defined if module is enabled + $enabled=true; + $part=strtolower(eregi_replace('^mod','',$modulename)); if (empty($conf->$part->enabled)) $enabled=false; if ($enabled) - { + { // Chargement de la classe - $file = $dir."/".$modulename.".class.php"; - $classname = $modulename; - require_once($file); - $module = new $classname($this->db); + $file = $dir."/".$modulename.".class.php"; + $classname = $modulename; + require_once($file); + $module = new $classname($this->db); - if (is_array($module->import_code)) - { - foreach($module->import_code as $r => $value) - { - if ($filter && ($filter != $module->import_code[$r])) continue; + if (is_array($module->import_code)) + { + foreach($module->import_code as $r => $value) + { + if ($filter && ($filter != $module->import_code[$r])) continue; - // Test if permissions are ok - /*$perm=$module->import_permission[$r][0]; - //print_r("$perm[0]-$perm[1]-$perm[2]
"); - if ($perm[2]) - { - $bool=$user->rights->$perm[0]->$perm[1]->$perm[2]; - } - else - { - $bool=$user->rights->$perm[0]->$perm[1]; - } - if ($perm[0]=='user' && $user->admin) $bool=true; - //print $bool." $perm[0]"."
"; + // Test if permissions are ok + /*$perm=$module->import_permission[$r][0]; + //print_r("$perm[0]-$perm[1]-$perm[2]
"); + if ($perm[2]) + { + $bool=$user->rights->$perm[0]->$perm[1]->$perm[2]; + } + else + { + $bool=$user->rights->$perm[0]->$perm[1]; + } + if ($perm[0]=='user' && $user->admin) $bool=true; + //print $bool." $perm[0]"."
"; */ - // Permissions ok - // if ($bool) - // { - // Charge fichier lang en rapport - $langtoload=$module->getLangFilesArray(); - if (is_array($langtoload)) - { - foreach($langtoload as $key) - { - $langs->load($key); - } - } + // Permissions ok + // if ($bool) + // { + // Charge fichier lang en rapport + $langtoload=$module->getLangFilesArray(); + if (is_array($langtoload)) + { + foreach($langtoload as $key) + { + $langs->load($key); + } + } - // Module - $this->array_import_module[$i]=$module; - // Permission - $this->array_import_perms[$i]=$user->admin; - // Icon - $this->array_import_icon[$i]=(isset($module->import_icon[$r])?$module->import_icon[$r]:$module->picto); - // Code du dataset export - $this->array_import_code[$i]=$module->import_code[$r]; - // Libelle du dataset export - $this->array_import_label[$i]=$module->getDatasetLabel($r); - // Tableau des champ a exporter (cle=champ, valeur=libelle) - $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_alias[$i]=$module->import_alias_array[$r]; - // Tableau des operations speciales sur champ - $this->array_import_special[$i]=$module->import_special_array[$r]; + // Module + $this->array_import_module[$i]=$module; + // Permission + $this->array_import_perms[$i]=$user->admin; + // Icon + $this->array_import_icon[$i]=(isset($module->import_icon[$r])?$module->import_icon[$r]:$module->picto); + // Code du dataset export + $this->array_import_code[$i]=$module->import_code[$r]; + // Libelle du dataset export + $this->array_import_label[$i]=$module->getDatasetLabel($r); + // Tableau des champ a exporter (cle=champ, valeur=libelle) + $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_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]; - // 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++; - // } - } - } - } - } - } + 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++; + // } + } + } + } + } + } } - } - closedir($handle); - } + } + closedir($handle); + } - /* - * \brief Importe un fichier clients + /** + * \brief Lance la generation du fichier example + * \param user User qui exporte + * \param model Modele d'export + * \param $headerlinefields Array of values for first line of example file + * \param $contentlinevalues Array of values for content line of example file + * \remarks Les tableaux array_export_xxx sont deja chargees pour le bon datatoexport + * aussi le parametre datatoexport est inutilise */ - function ImportClients($file) + function build_example_file($user, $model, $headerlinefields, $contentlinevalues) { - $this->nb_import_ok = 0; - $this->nb_import_ko = 0; - $this->nb_import = 0; + global $conf,$langs; - dol_syslog("Import::ImportClients($file)", LOG_DEBUG); + $indice=0; - $this->ReadFile($file); + dol_syslog("Import::build_example_file ".$model); - foreach ($this->lines as $this->line) - { - $societe = new Societe($this->db); + // Creation de la classe d'import du model Import_XXX + $dir = DOL_DOCUMENT_ROOT . "/includes/modules/import/"; + $file = "import_".$model.".modules.php"; + $classname = "Import".$model; + require_once($dir.$file); + $objmodel = new $classname($this->db); - $this->SetInfosTiers($societe); + $outputlangs=$langs; // Lang for output + $s=''; - $societe->client = 1; - $societe->tva_assuj = $this->line[12]; - $societe->code_client = $this->line[13]; - $societe->tva_intra = $this->line[14]; + // Genere en-tete + $s.=$objmodel->write_header_example($outputlangs); - $this->nb_import++; + // Genere ligne de titre + $s.=$objmodel->write_title_example($outputlangs,$headerlinefields); - if ( $societe->create($user) == 0) - { - dol_syslog("Import::ImportClients ".$societe->nom." SUCCESS", LOG_DEBUG); - $this->nb_import_ok++; - } - else - { - dol_syslog("Import::ImportClients ".$societe->nom." ERROR", LOG_ERR); - $this->nb_import_ko++; - } - } + // Genere ligne de titre + $s.=$objmodel->write_record_example($outputlangs,$contentlinevalues); + // Genere pied de page + $s.=$objmodel->write_footer_example($outputlangs); + + return $s; } - - - function SetInfosTiers(&$obj) - { - $obj->nom = $this->line[0]; - $obj->adresse = $this->line[1]; - - if (strlen(trim($this->line[2])) > 0) - $obj->adresse .= "\n". trim($this->line[2]); - - if (strlen(trim($this->line[3])) > 0) - $obj->adresse .= "\n". trim($this->line[3]); - - $obj->cp = $this->line[4]; - $obj->ville = $this->line[5]; - $obj->tel = $this->line[6]; - $obj->fax = $this->line[7]; - $obj->email = $this->line[8]; - $obj->url = $this->line[9]; - $obj->siren = $this->line[10]; - $obj->siret = $this->line[11]; - } - - - function ReadFile($file) - { - $this->errno = 0; - - if (is_readable($file)) - { - dol_syslog("Import::ReadFile Lecture du fichier $file", LOG_DEBUG); - - $line = 0; - $hf = fopen ($file, "r"); - $line = 0; - $i=0; - - $this->lines = array(); - - - while (!feof($hf) ) - { - $cont = fgets($hf, 1024); - - if (strlen(trim($cont)) > 0) - { - $this->lines[$i] = explode(";", $cont); - } - $i++; - - } - } - else - { - $this->errno = -2; - } - - return $errno; - } - } ?> diff --git a/htdocs/imports/import.php b/htdocs/imports/import.php index 504263ff5df..addff0ad31f 100644 --- a/htdocs/imports/import.php +++ b/htdocs/imports/import.php @@ -199,8 +199,6 @@ if ($step == 3 && $action == 'select_model') * Affichage Pages des Etapes */ -$objmodelimport=new ModeleImports(); - if ($step == 1 || ! $datatoimport) { @@ -338,7 +336,7 @@ if ($step == 2 && $datatoimport) print ''; print ''.img_picto_common($key,$objmodelimport->getPicto($key)).''; print ''.$objmodelimport->getDriverLabel($key).''; - print ''.$langs->trans("DownloadEmptyExample").''; + print ''.$langs->trans("DownloadEmptyExample").''; //print ''.$objmodelimport->getLibLabel($key).''.$objmodelimport->getLibVersion($key).''; print ''; } @@ -432,6 +430,7 @@ if ($step == 3 && $datatoimport) 2=>array('name'=>'bb','example1'=>'valb1','example2'=>'valb2') ); + // Load targets fields in database $fieldstarget=$objimport->array_import_fields[0]; @@ -512,7 +511,7 @@ if ($step == 3 && $datatoimport) print '
'; - // Combo list of import models + // List of import models print '
'; print ''; print ''; @@ -919,7 +918,7 @@ function show_elem($fieldssource,$pos,$var,$key) if (empty($key)) { print ''; - print img_picto($langs->trans("MoveBox",$pos),'uparrow','class="boxhandle" style="cursor:move;"'); + print img_picto(($pos>0?$langs->trans("MoveField",$pos):''),'uparrow','class="boxhandle" style="cursor:move;"'); print ''; print ''; print $langs->trans("NoFields"); @@ -939,7 +938,7 @@ function show_elem($fieldssource,$pos,$var,$key) //print ''.img_file('','').''; print ''; // The image must have the class 'boxhandle' beause it's value used in DOM draggable objects to define the area used to catch the full object - print img_picto($langs->trans("MoveBox",$pos),'uparrow','class="boxhandle" style="cursor:move;"'); + print img_picto($langs->trans("MoveField",$pos),'uparrow','class="boxhandle" style="cursor:move;"'); print ''; print ''; print $langs->trans("Field").' '.$key.': '; diff --git a/htdocs/includes/modules/import/import_csv.modules.php b/htdocs/includes/modules/import/import_csv.modules.php index 8f2c281df6c..3c7a76277a1 100644 --- a/htdocs/includes/modules/import/import_csv.modules.php +++ b/htdocs/includes/modules/import/import_csv.modules.php @@ -68,7 +68,7 @@ class ImportCsv extends ModeleImports $this->version_lib=DOL_VERSION; $this->separator=','; - if (! empty($conf->global->EXPORT_CSV_SEPARATOR_TO_USE)) $this->separator=$conf->global->EXPORT_CSV_SEPARATOR_TO_USE; + if (! empty($conf->global->IMPORT_CSV_SEPARATOR_TO_USE)) $this->separator=$conf->global->IMPORT_CSV_SEPARATOR_TO_USE; } function getDriverId() @@ -102,6 +102,48 @@ class ImportCsv extends ModeleImports } + /** + * \brief Output header of an example file for this format + * \param langs Output language + */ + function write_header_example($outputlangs) + { + return ''; + } + + /** + * \brief Output title line of an example file for this format + * \param langs Output language + */ + function write_title_example($outputlangs,$headerlinefields) + { + $s=''; + $s.=join($this->separator,$headerlinefields); + return $s."\n"; + } + + /** + * \brief Output record of an example file for this format + * \param langs Output language + */ + function write_record_example($outputlangs,$contentlinevalues) + { + $s=''; + $s.=join($this->separator,$contentlinevalues); + return $s."\n"; + } + + /** + * \brief Output footer of an example file for this format + * \param langs Output language + */ + function write_footer_example($outputlangs) + { + return ''; + } + + + /** * \brief Open output file * \param file Path of filename diff --git a/htdocs/includes/modules/import/modules_import.php b/htdocs/includes/modules/import/modules_import.php index 78f9b182f2f..daf9cd576b7 100644 --- a/htdocs/includes/modules/import/modules_import.php +++ b/htdocs/includes/modules/import/modules_import.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2005-2009 Laurent Destailleur * Copyright (C) 2005-2007 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -24,7 +24,6 @@ * \brief File of parent class for import file readers * \version $Id$ */ - require_once(DOL_DOCUMENT_ROOT.'/lib/functions.lib.php'); diff --git a/htdocs/includes/modules/modProduit.class.php b/htdocs/includes/modules/modProduit.class.php index 32a2dfd622d..d587bb5e902 100644 --- a/htdocs/includes/modules/modProduit.class.php +++ b/htdocs/includes/modules/modProduit.class.php @@ -155,6 +155,7 @@ class modProduit extends DolibarrModules //$this->import_permission[$r]=array(array("societe","import")); $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.'produit as s'; $this->import_sql_end[$r] =''; diff --git a/htdocs/includes/modules/modSociete.class.php b/htdocs/includes/modules/modSociete.class.php index bffeca9076e..58e2968ed6a 100644 --- a/htdocs/includes/modules/modSociete.class.php +++ b/htdocs/includes/modules/modSociete.class.php @@ -191,6 +191,7 @@ class modSociete extends DolibarrModules $r++; $this->export_code[$r]=$this->rights_class.'_'.$r; $this->export_label[$r]='ExportDataset_company_1'; + $this->export_icon[$r]='company'; $this->export_permission[$r]=array(array("societe","export")); $this->export_fields_array[$r]=array('s.rowid'=>"Id",'s.nom'=>"Name",'s.prefix_comm'=>"Prefix",'s.client'=>"Customer",'s.fournisseur'=>"Supplier",'s.datec'=>"DateCreation",'s.tms'=>"DateLastModification",'s.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode",'s.address'=>"Address",'s.cp'=>"Zip",'s.ville'=>"Town",'p.libelle'=>"Country",'p.code'=>"CountryCode",'s.tel'=>"Phone",'s.fax'=>"Fax",'s.url'=>"Url",'s.email'=>"Email",'s.siret'=>"IdProf1",'s.siren'=>"IdProf2",'s.ape'=>"IdProf3",'s.idprof4'=>"IdProf4",'s.tva_intra'=>"VATIntraShort",'s.capital'=>"Capital",'s.note'=>"Note",'t.libelle'=>"ThirdPartyType",'ce.code'=>"Effectif","cfj.libelle"=>"JuridicalStatus",'s.fk_prospectlevel'=>'ProspectLevel','fk_stcomm'=>'ProspectStatus'); $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>"company",'s.prefix_comm'=>"company",'s.client'=>"company",'s.fournisseur'=>"company",'s.datec'=>"company",'s.tms'=>"company",'s.code_client'=>"company",'s.code_fournisseur'=>"company",'s.address'=>"company",'s.cp'=>"company",'s.ville'=>"company",'p.libelle'=>"company",'p.code'=>"company",'s.tel'=>"company",'s.fax'=>"company",'s.url'=>"company",'s.email'=>"company",'s.siret'=>"company",'s.siren'=>"company",'s.ape'=>"company",'s.idprof4'=>"company",'s.tva_intra'=>"company",'s.capital'=>"company",'s.note'=>"company",'t.libelle'=>"company",'ce.code'=>"company","cfj.libelle"=>"company",'s.fk_prospectlevel'=>'company','fk_stcomm'=>'company'); @@ -229,9 +230,11 @@ class modSociete extends DolibarrModules $r++; $this->import_code[$r]=$this->rights_class.'_'.$r; $this->import_label[$r]='ImportDataset_company_1'; + $this->import_icon[$r]='company'; //$this->import_permission[$r]=array(array("societe","export")); - $this->import_fields_array[$r]=array('s.nom'=>"Name",'s.prefix_comm'=>"Prefix",'s.client'=>"Customer",'s.fournisseur'=>"Supplier",'s.datec'=>"DateCreation",'s.tms'=>"DateLastModification",'s.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode",'s.address'=>"Address",'s.cp'=>"Zip",'s.ville'=>"Town",'p.libelle'=>"Country",'p.code'=>"CountryCode",'s.tel'=>"Phone",'s.fax'=>"Fax",'s.url'=>"Url",'s.email'=>"Email",'s.siret'=>"IdProf1",'s.siren'=>"IdProf2",'s.ape'=>"IdProf3",'s.idprof4'=>"IdProf4",'s.tva_intra'=>"VATIntraShort",'s.capital'=>"Capital",'s.note'=>"Note",'t.libelle'=>"ThirdPartyType",'ce.code'=>"Effectif","cfj.libelle"=>"JuridicalStatus",'s.fk_prospectlevel'=>'ProspectLevel','fk_stcomm'=>'ProspectStatus'); - $this->import_entities_array[$r]=array('s.nom'=>"company",'s.prefix_comm'=>"company",'s.client'=>"company",'s.fournisseur'=>"company",'s.datec'=>"company",'s.tms'=>"company",'s.code_client'=>"company",'s.code_fournisseur'=>"company",'s.address'=>"company",'s.cp'=>"company",'s.ville'=>"company",'p.libelle'=>"company",'p.code'=>"company",'s.tel'=>"company",'s.fax'=>"company",'s.url'=>"company",'s.email'=>"company",'s.siret'=>"company",'s.siren'=>"company",'s.ape'=>"company",'s.idprof4'=>"company",'s.tva_intra'=>"company",'s.capital'=>"company",'s.note'=>"company",'t.libelle'=>"company",'ce.code'=>"company","cfj.libelle"=>"company",'s.fk_prospectlevel'=>'company','fk_stcomm'=>'company'); + $this->import_fields_array[$r]=array('s.nom'=>"Name",'s.prefix_comm'=>"Prefix",'s.client'=>"Customer",'s.fournisseur'=>"Supplier",'s.datec'=>"DateCreation",'s.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode",'s.address'=>"Address",'s.cp'=>"Zip",'s.ville'=>"Town",'p.code'=>"CountryCode",'s.tel'=>"Phone",'s.fax'=>"Fax",'s.url'=>"Url",'s.email'=>"Email",'s.siret'=>"IdProf1",'s.siren'=>"IdProf2",'s.ape'=>"IdProf3",'s.idprof4'=>"IdProf4",'s.tva_intra'=>"VATIntraShort",'s.capital'=>"Capital",'s.note'=>"Note",'s.fk_type'=>"ThirdPartyType",'s.fk_effectif'=>"Effectif","s.fk_status"=>"JuridicalStatus",'s.fk_prospectlevel'=>'ProspectLevel','s.fk_stcomm'=>'ProspectStatus'); + $this->import_entities_array[$r]=array('s.nom'=>"company",'s.prefix_comm'=>"company",'s.client'=>"company",'s.fournisseur'=>"company",'s.datec'=>"company",'s.code_client'=>"company",'s.code_fournisseur'=>"company",'s.address'=>"company",'s.cp'=>"company",'s.ville'=>"company",'p.code'=>"company",'s.tel'=>"company",'s.fax'=>"company",'s.url'=>"company",'s.email'=>"company",'s.siret'=>"company",'s.siren'=>"company",'s.ape'=>"company",'s.idprof4'=>"company",'s.tva_intra'=>"company",'s.capital'=>"company",'s.note'=>"company",'s.fk_type'=>"company",'s.fk_effectif'=>"company","s.fk_status"=>"company",'s.fk_prospectlevel'=>'company','s.fk_stcomm'=>'company'); + $this->import_examplevalues_array[$r]=array('s.nom'=>"A company",'s.prefix_comm'=>"comp",'s.client'=>'0 or 1','s.fournisseur'=>'0 or 1','s.datec'=>dol_print_date(mktime(),'YYYY-MM-DD'),'s.code_client'=>"CU01-0001",'s.code_fournisseur'=>"SU01-0001",'s.address'=>"61 jump street",'s.cp'=>"123456",'s.ville'=>"Big town",'p.code'=>"US",'s.tel'=>"0101010101",'s.fax'=>"0101010102",'s.url'=>"http://mycompany.com",'s.email'=>"test@mycompany.com",'s.siret'=>"",'s.siren'=>"",'s.ape'=>"",'s.idprof4'=>"",'s.tva_intra'=>"FR0123456789",'s.capital'=>"10000",'s.note'=>"This is an example of note for record",'s.fk_type'=>"XXX",'s.fk_effectif'=>"YYY","s.fk_status"=>"ZZZ",'s.fk_prospectlevel'=>'AAA','s.fk_stcomm'=>'BBB'); $this->import_sql_start[$r]='INSERT INTO '.MAIN_DB_PREFIX.'societe as s'; $this->import_sql_end[$r] =''; diff --git a/htdocs/langs/en_US/exports.lang b/htdocs/langs/en_US/exports.lang index 267875c1d12..b19f2090938 100644 --- a/htdocs/langs/en_US/exports.lang +++ b/htdocs/langs/en_US/exports.lang @@ -62,4 +62,5 @@ DownloadEmptyExample=Download example of empty source file ChooseFileToImport=Upload file then click on picto %s to select file as source import file... FieldsInSourceFile=Fields in source file FieldsInTargetDatabase=Target fields in Dolibarr database -NoFields=No fields \ No newline at end of file +NoFields=No fields +MoveField=Move field column number %s \ No newline at end of file diff --git a/htdocs/langs/fr_FR/exports.lang b/htdocs/langs/fr_FR/exports.lang index ddb2a6c4723..152f3651b3a 100644 --- a/htdocs/langs/fr_FR/exports.lang +++ b/htdocs/langs/fr_FR/exports.lang @@ -62,4 +62,5 @@ ChooseFileToImport=Ajouter le fichier à importer puis cliquez sur le picto %s p DownloadEmptyExample=Télécharger fichier vierge exemple FieldsInSourceFile=Champs dans le fichier source FieldsInTargetDatabase=Champs cibles dans la base Dolibarr -NoFields=Aucun champ \ No newline at end of file +NoFields=Aucun champ +MoveField=Déplacer champ colonne numéro %s \ No newline at end of file