2
0
forked from Wavyzz/dolibarr

Work on import module

This commit is contained in:
Laurent Destailleur
2009-10-03 12:08:48 +00:00
parent 8753ffa007
commit d9ecd2347a
9 changed files with 112 additions and 50 deletions

View File

@@ -171,12 +171,41 @@ class Export
} }
} }
/** /**
* \brief Lance la generation du fichier * \brief Build the sql export request
* \param user User qui exporte * \param indice Indice of export
* \param model Modele d'export * \param array_selected Filter on array of fields to export
* \param datatoexport Lot de donnee a exporter * \remarks Les tableaux array_export_xxx sont deja chargees pour le bon datatoexport
* \param array_selected Tableau des champs a exporter * aussi le parametre datatoexport est inutilise
*/
function build_sql($indice,$array_selected)
{
// Build the sql request
$sql=$this->array_export_sql_start[$indice];
$i=0;
//print_r($array_selected);
foreach ($this->array_export_alias[$indice] as $key => $value)
{
if (! array_key_exists($key, $array_selected)) continue; // Field not selected
if ($i > 0) $sql.=', ';
else $i++;
$newfield=$key.' as '.$value;
$sql.=$newfield;
}
$sql.=$this->array_export_sql_end[$indice];
return $sql;
}
/**
* \brief Build export file
* \param user User that export
* \param model Export format
* \param datatoexport Name of dataset to export
* \param array_selected Filter on array of fields to export
* \remarks Les tableaux array_export_xxx sont deja chargees pour le bon datatoexport * \remarks Les tableaux array_export_xxx sont deja chargees pour le bon datatoexport
* aussi le parametre datatoexport est inutilise * aussi le parametre datatoexport est inutilise
*/ */
@@ -196,21 +225,7 @@ class Export
require_once($dir.$file); require_once($dir.$file);
$objmodel = new $classname($db); $objmodel = new $classname($db);
// Build the sql request $sql=$this->build_sql($indice,$array_selected);
$sql=$this->array_export_sql_start[$indice];
$i=0;
//print_r($array_selected);
foreach ($this->array_export_alias[$indice] as $key => $value)
{
if (! array_key_exists($key, $array_selected)) continue; // Field not selected
if ($i > 0) $sql.=', ';
else $i++;
$newfield=$key.' as '.$value;
$sql.=$newfield;
}
$sql.=$this->array_export_sql_end[$indice];
// Run the sql // Run the sql
$this->sqlusedforexport=$sql; $this->sqlusedforexport=$sql;

View File

@@ -379,7 +379,7 @@ if ($step == 2 && $datatoexport)
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Entities").'</td>'; print '<td>'.$langs->trans("Entities").'</td>';
print '<td>'.$langs->trans("ExportableFields").'</td>'; print '<td>'.$langs->trans("ExportableFields").'</td>';
print '<td width="12" align="middle">'; print '<td width="100" align="center">';
print '<a title='.$langs->trans("All").' alt='.$langs->trans("All").' href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=selectfield&field=all">'.$langs->trans("All")."</a>"; print '<a title='.$langs->trans("All").' alt='.$langs->trans("All").' href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=selectfield&field=all">'.$langs->trans("All")."</a>";
print '/'; print '/';
print '<a title='.$langs->trans("None").' alt='.$langs->trans("None").' href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=unselectfield&field=all">'.$langs->trans("None")."</a>"; print '<a title='.$langs->trans("None").' alt='.$langs->trans("None").' href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=unselectfield&field=all">'.$langs->trans("None")."</a>";
@@ -389,6 +389,8 @@ if ($step == 2 && $datatoexport)
// Champs exportables // Champs exportables
$fieldsarray=$objexport->array_export_fields[0]; $fieldsarray=$objexport->array_export_fields[0];
// Select request if all fields are selected
$sqlmaxforexport=$objexport->build_sql(0,array());
# $this->array_export_module[0]=$module; # $this->array_export_module[0]=$module;
# $this->array_export_code[0]=$module->export_code[$r]; # $this->array_export_code[0]=$module->export_code[$r];
@@ -418,13 +420,27 @@ if ($step == 2 && $datatoexport)
// Selected fields // Selected fields
print '<td>&nbsp;</td>'; print '<td>&nbsp;</td>';
print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=unselectfield&field='.$code.'">'.img_left().'</a></td>'; print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=unselectfield&field='.$code.'">'.img_left().'</a></td>';
print '<td>'.$langs->trans($label).' ('.$code.')</td>'; print '<td>';
$text=$langs->trans($label);
$tablename=getablenamefromfield($code,$sqlmaxforexport);
$htmltext =$langs->trans("Table").": <b>".$tablename."</b><br>";
$htmltext.=$langs->trans("Field").': <b>'.$code."</b><br>";
print $html->textwithpicto($text,$htmltext);
//print ' ('.$code.')';
print '</td>';
$bit=1; $bit=1;
} }
else else
{ {
// Fields not selected // Fields not selected
print '<td>'.$langs->trans($label).' ('.$code.')</td>'; print '<td>';
$text=$langs->trans($label);
$tablename=getablenamefromfield($code,$sqlmaxforexport);
$htmltext =$langs->trans("Table").": <b>".$tablename."</b><br>";
$htmltext.=$langs->trans("Field").': <b>'.$code."</b><br>";
print $html->textwithpicto($text,$htmltext);
//print ' ('.$code.')';
print '</td>';
print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=selectfield&field='.$code.'">'.img_right().'</a></td>'; print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=selectfield&field='.$code.'">'.img_right().'</a></td>';
print '<td>&nbsp;</td>'; print '<td>&nbsp;</td>';
$bit=0; $bit=0;
@@ -452,7 +468,7 @@ if ($step == 2 && $datatoexport)
} }
else else
{ {
print '<a class="butActionRefused" href="#">'.$langs->trans("NextStep").'</a>'; print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("SelectAtLeastOneField")).'">'.$langs->trans("NextStep").'</a>';
} }
print '</div>'; print '</div>';
@@ -506,7 +522,7 @@ if ($step == 3 && $datatoexport)
$list=''; $list='';
foreach($array_selected as $code=>$value) foreach($array_selected as $code=>$value)
{ {
$list.=($list?',':''); $list.=($list?', ':'');
$list.=$langs->trans($objexport->array_export_fields[0][$code]); $list.=$langs->trans($objexport->array_export_fields[0][$code]);
} }
print '<td>'.$list.'</td></tr>'; print '<td>'.$list.'</td></tr>';
@@ -514,6 +530,9 @@ if ($step == 3 && $datatoexport)
print '</table>'; print '</table>';
print '<br>'; print '<br>';
// Select request if all fields are selected
$sqlmaxforexport=$objexport->build_sql(0,array());
print $langs->trans("ChooseFieldsOrdersAndTitle").'<br>'; print $langs->trans("ChooseFieldsOrdersAndTitle").'<br>';
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
@@ -521,8 +540,8 @@ if ($step == 3 && $datatoexport)
print '<td>'.$langs->trans("Entities").'</td>'; print '<td>'.$langs->trans("Entities").'</td>';
print '<td>'.$langs->trans("ExportedFields").'</td>'; print '<td>'.$langs->trans("ExportedFields").'</td>';
print '<td align="right" colspan="2">'.$langs->trans("Position").'</td>'; print '<td align="right" colspan="2">'.$langs->trans("Position").'</td>';
print '<td>&nbsp;</td>'; //print '<td>&nbsp;</td>';
print '<td>'.$langs->trans("FieldsTitle").'</td>'; //print '<td>'.$langs->trans("FieldsTitle").'</td>';
print '</tr>'; print '</tr>';
$var=true; $var=true;
@@ -537,7 +556,14 @@ if ($step == 3 && $datatoexport)
print '<td>'.img_object('',$entityicon).' '.$langs->trans($entitylang).'</td>'; print '<td>'.img_object('',$entityicon).' '.$langs->trans($entitylang).'</td>';
print '<td>'.$langs->trans($objexport->array_export_fields[0][$code]).' ('.$code.')</td>'; print '<td>';
$text=$langs->trans($objexport->array_export_fields[0][$code]);
$tablename=getablenamefromfield($code,$sqlmaxforexport);
$htmltext =$langs->trans("Table").": <b>".$tablename."</b><br>";
$htmltext.=$langs->trans("Field").': <b>'.$code."</b><br>";
print $html->textwithpicto($text,$htmltext);
//print ' ('.$code.')';
print '</td>';
print '<td align="right" width="100">'; print '<td align="right" width="100">';
print $value.' '; print $value.' ';
@@ -546,9 +572,8 @@ if ($step == 3 && $datatoexport)
if ($value > 1) print '<a href="'.$_SERVER["PHP_SELF"].'?step=3&datatoexport='.$datatoexport.'&action=upfield&field='.$code.'">'.img_up().'</a>'; if ($value > 1) print '<a href="'.$_SERVER["PHP_SELF"].'?step=3&datatoexport='.$datatoexport.'&action=upfield&field='.$code.'">'.img_up().'</a>';
print '</td>'; print '</td>';
print '<td>&nbsp;</td>'; //print '<td>&nbsp;</td>';
//print '<td>'.$langs->trans($objexport->array_export_fields[0][$code]).'</td>';
print '<td>'.$langs->trans($objexport->array_export_fields[0][$code]).'</td>';
print '</tr>'; print '</tr>';
} }
@@ -684,7 +709,7 @@ if ($step == 4 && $datatoexport)
$list=''; $list='';
foreach($array_selected as $code=>$label) foreach($array_selected as $code=>$label)
{ {
$list.=($list?',':''); $list.=($list?', ':'');
$list.=$langs->trans($objexport->array_export_fields[0][$code]); $list.=$langs->trans($objexport->array_export_fields[0][$code]);
} }
print '<td>'.$list.'</td></tr>'; print '<td>'.$list.'</td></tr>';
@@ -763,4 +788,25 @@ print '<br>';
$db->close(); $db->close();
llxFooter('$Date$ - $Revision$'); llxFooter('$Date$ - $Revision$');
/**
* \brief Return table name of an alias. For this, we look for the "tablename as alias" in sql string.
* \param code Alias.Fieldname
* \param sqlmaxforexport SQL request to parse
*/
function getablenamefromfield($code,$sqlmaxforexport)
{
$newsql=$sqlmaxforexport;
$newsql=eregi_replace('^.* FROM ','',$newsql);
$newsql=eregi_replace(' WHERE .*$','',$newsql);
$alias=eregi_replace('\..*$','',$code);
//print $newsql.' '.$alias;
if (eregi('([a-zA-Z_]+) as '.$alias.'[, \)]',$newsql,$reg))
{
return $reg[1];
}
else return '';
}
?> ?>

View File

@@ -1232,7 +1232,7 @@ function show_elem($fieldssource,$i,$pos,$key,$var)
print '</td>'; print '</td>';
print '<td style="font-weight: normal">'; print '<td style="font-weight: normal">';
print $langs->trans("Field").' '.$pos; print $langs->trans("Field").' '.$pos;
if (isset($fieldssource[$pos]['example1'])) print ' (<i>'.$fieldssource[$pos]['example1'].'</i>)'; if (! empty($fieldssource[$pos]['example1'])) print ' (<i>'.$fieldssource[$pos]['example1'].'</i>)';
print '</td>'; print '</td>';
} }
print '</tr>'; print '</tr>';

View File

@@ -63,7 +63,7 @@ class ExportCsv extends ModeleExports
$this->id='csv'; // Same value then xxx in file name export_xxx.modules.php $this->id='csv'; // Same value then xxx in file name export_xxx.modules.php
$this->label='Csv'; // Label of driver $this->label='Csv'; // Label of driver
$this->desc='<b>Comma Separated Value</b> file format (.csv). This is a text file format.<br>Fields are separated by separator [ '.$this->separator.' ]. If separator is found inside a field content, field is rounded by round character [ '.$this->enclosure.' ]. Escape character to escape round character is [ '.$this->escape.' ].'; $this->desc='<b>Comma Separated Value</b> file format (.csv).<br>This is a text file format where fields are separated by separator [ '.$this->separator.' ]. If separator is found inside a field content, field is rounded by round character [ '.$this->enclosure.' ]. Escape character to escape round character is [ '.$this->escape.' ].';
$this->extension='csv'; // Extension for generated file by this driver $this->extension='csv'; // Extension for generated file by this driver
$this->picto='mime/other'; // Picto $this->picto='mime/other'; // Picto
$ver=split(' ','$Revision$'); $ver=split(' ','$Revision$');

View File

@@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2006-2008 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2006-2009 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -18,11 +18,11 @@
*/ */
/** /**
\file htdocs/includes/modules/export/export_excel.modules.php * \file htdocs/includes/modules/export/export_excel.modules.php
\ingroup export * \ingroup export
\brief Fichier de la classe permettant de g<>n<EFBFBD>rer les export au format Excel * \brief Fichier de la classe permettant de g<>n<EFBFBD>rer les export au format Excel
\author Laurent Destailleur * \author Laurent Destailleur
\version $Id$ * \version $Id$
*/ */
require_once(DOL_DOCUMENT_ROOT."/includes/modules/export/modules_export.php"); require_once(DOL_DOCUMENT_ROOT."/includes/modules/export/modules_export.php");
@@ -32,10 +32,9 @@ require_once(PHP_WRITEEXCEL_PATH."/functions.writeexcel_utility.inc.php");
/** /**
\class ExportExcel * \class ExportExcel
\brief Classe permettant de g<>n<EFBFBD>rer les export au format Excel * \brief Class to build export files with Excel format
*/ */
class ExportExcel extends ModeleExports class ExportExcel extends ModeleExports
{ {
var $id; var $id;
@@ -53,8 +52,8 @@ class ExportExcel extends ModeleExports
/** /**
\brief Constructeur * \brief Constructor
\param db Handler acc<63>s base de donn<6E>e * \param db databse handler
*/ */
function ExportExcel($db) function ExportExcel($db)
{ {
@@ -63,7 +62,7 @@ class ExportExcel extends ModeleExports
$this->id='excel'; // Same value then xxx in file name export_xxx.modules.php $this->id='excel'; // Same value then xxx in file name export_xxx.modules.php
$this->label='Excel'; // Label of driver $this->label='Excel'; // Label of driver
$this->desc='Native <b>Excel 95</b> file format (.xls)'; $this->desc='<b>Excel</b> file format (.xls)<br>This is native Excel 95 format.';
$this->extension='xls'; // Extension for generated file by this driver $this->extension='xls'; // Extension for generated file by this driver
$this->picto='mime/xls'; // Picto $this->picto='mime/xls'; // Picto
$ver=split(' ','$Revision$'); $ver=split(' ','$Revision$');

View File

@@ -58,7 +58,7 @@ class ExportTsv extends ModeleExports
$this->id='tsv'; // Same value then xxx in file name export_xxx.modules.php $this->id='tsv'; // Same value then xxx in file name export_xxx.modules.php
$this->label='Tsv'; // Label of driver $this->label='Tsv'; // Label of driver
$this->desc='<b>Tab Separated Value</b> file format (.tsv)'; $this->desc='<b>Tab Separated Value</b> file format (.tsv)<br>This is a text file format where fields are separated by separator [tab].';
$this->extension='tsv'; // Extension for generated file by this driver $this->extension='tsv'; // Extension for generated file by this driver
$this->picto='mime/other'; // Picto $this->picto='mime/other'; // Picto
$ver=split(' ','$Revision$'); $ver=split(' ','$Revision$');

View File

@@ -63,7 +63,7 @@ class ImportCsv extends ModeleImports
$this->id='csv'; // Same value then xxx in file name export_xxx.modules.php $this->id='csv'; // Same value then xxx in file name export_xxx.modules.php
$this->label='Csv'; // Label of driver $this->label='Csv'; // Label of driver
$this->desc='<b>Comma Separated Value</b> file format (.csv). This is a text file format.<br>Fields are separated by separator [ '.$this->separator.' ]. If separator is found inside a field content, field is rounded by round character [ '.$this->enclosure.' ]. Escape character to escape round character is [ '.$this->escape.' ].'; $this->desc='<b>Comma Separated Value</b> file format (.csv).<br>This is a text file format where fields are separated by separator [ '.$this->separator.' ]. If separator is found inside a field content, field is rounded by round character [ '.$this->enclosure.' ]. Escape character to escape round character is [ '.$this->escape.' ].';
$this->extension='csv'; // Extension for generated file by this driver $this->extension='csv'; // Extension for generated file by this driver
$this->picto='mime/other'; // Picto $this->picto='mime/other'; // Picto
$ver=split(' ','$Revision$'); $ver=split(' ','$Revision$');

View File

@@ -29,7 +29,7 @@ ChooseFieldsOrdersAndTitle=Choose fields order...
FieldsOrder=Fields order FieldsOrder=Fields order
FieldsTitle=Fields title FieldsTitle=Fields title
ChooseExportFormat=Choose export format ChooseExportFormat=Choose export format
NowClickToGenerateToBuildExportFile=Now, click on "Generate" to build export file... NowClickToGenerateToBuildExportFile=Now, select file format in combo box and click on "Generate" to build export file...
AvailableFormats=Available formats AvailableFormats=Available formats
LibraryShort=Library LibraryShort=Library
LibraryUsed=Library used LibraryUsed=Library used
@@ -81,3 +81,4 @@ FieldNeedSource=This fiels in database require a data from source file
SomeMandatoryFieldHaveNoSource=Some mandatory fields have no source from data file SomeMandatoryFieldHaveNoSource=Some mandatory fields have no source from data file
InformationOnSourceFile=Informations on source file InformationOnSourceFile=Informations on source file
InformationOnTargetTables=Informations on target fields InformationOnTargetTables=Informations on target fields
SelectAtLeastOneField=Switch at least one source field in the column of fields to export

View File

@@ -29,7 +29,7 @@ ChooseFieldsOrdersAndTitle=Choisissez l'ordre des champs...
FieldsOrder=Ordre des champs FieldsOrder=Ordre des champs
FieldsTitle=Titre champs FieldsTitle=Titre champs
ChooseExportFormat=Choisissez le format d'export ChooseExportFormat=Choisissez le format d'export
NowClickToGenerateToBuildExportFile=Maintenant, cliquez sur "Générer" pour générer le fichier export... NowClickToGenerateToBuildExportFile=Maintenant, sélectionner le format d'export dans la liste déroulante et cliquez sur "Générer" pour fabriquer le fichier export...
AvailableFormats=Formats dispo. AvailableFormats=Formats dispo.
LibraryShort=Librairie LibraryShort=Librairie
LibraryUsed=Librairie utilisée LibraryUsed=Librairie utilisée
@@ -81,3 +81,4 @@ FieldNeedSource=Ce champ en base requiert obligatoirement une donnée source
SomeMandatoryFieldHaveNoSource=Certains champs obligatoires n'ont pas de champ source issus du fichier SomeMandatoryFieldHaveNoSource=Certains champs obligatoires n'ont pas de champ source issus du fichier
InformationOnSourceFile=Informations sur le fichier source InformationOnSourceFile=Informations sur le fichier source
InformationOnTargetTables=Informations sur les champs cibles InformationOnTargetTables=Informations sur les champs cibles
SelectAtLeastOneField=Basculer au moins un champ source dans la colonne des champs à exporter