2
0
forked from Wavyzz/dolibarr

New: Possibilit de choisir les ordres des champs dans les exports

Debut de la gestion du format export csv.
This commit is contained in:
Laurent Destailleur
2006-01-21 19:08:36 +00:00
parent f1f919e71f
commit 8b5005ba16
8 changed files with 298 additions and 26 deletions

View File

@@ -173,7 +173,7 @@ if ($_GET["action"] == 'create')
print '<td>'; print '<td>';
$model=new ModelePDFPropales(); $model=new ModelePDFPropales();
$liste=$model->liste_modeles($db); $liste=$model->liste_modeles($db);
$form->select_array("modelpdf",$liste,$conf->global->PROPALE_ADDON_PDF); $form->select_array("model",$liste,$conf->global->PROPALE_ADDON_PDF);
print "</td></tr></table>"; print "</td></tr></table>";
print '<br>'; print '<br>';

View File

@@ -115,7 +115,7 @@ if ($_POST['action'] == 'add')
$propal->contactid = $_POST['contactidp']; $propal->contactid = $_POST['contactidp'];
$propal->projetidp = $_POST['projetidp']; $propal->projetidp = $_POST['projetidp'];
$propal->modelpdf = $_POST['modelpdf']; $propal->modelpdf = $_POST['model'];
$propal->author = $user->id; $propal->author = $user->id;
$propal->note = $_POST['note']; $propal->note = $_POST['note'];
@@ -136,7 +136,7 @@ if ($_POST['action'] == 'add')
*/ */
if ($id > 0) if ($id > 0)
{ {
propale_pdf_create($db, $id, $_POST['modelpdf']); propale_pdf_create($db, $id, $_POST['model']);
Header ('Location: propal.php?propalid='.$id); Header ('Location: propal.php?propalid='.$id);
exit; exit;
} }
@@ -331,8 +331,8 @@ if ($_POST['action'] == 'updateligne' && $user->rights->propale->creer && $_POST
if ($_POST['action'] == 'builddoc' && $user->rights->propale->creer) if ($_POST['action'] == 'builddoc' && $user->rights->propale->creer)
{ {
$propal = new Propal($db, 0, $_GET['propalid']); $propal = new Propal($db, 0, $_GET['propalid']);
$propal->set_pdf_model($user, $_POST['modelpdf']); $propal->set_pdf_model($user, $_POST['model']);
propale_pdf_create($db, $_GET['propalid'], $_POST['modelpdf']); propale_pdf_create($db, $_GET['propalid'], $_POST['model']);
} }

View File

@@ -547,9 +547,9 @@ if ($_POST['action'] == 'send' || $_POST['action'] == 'relance')
} }
/* /*
* G<>n<EFBFBD>rer ou reg<65>n<EFBFBD>rer le PDF * G<>n<EFBFBD>rer ou reg<65>n<EFBFBD>rer le document PDF
*/ */
if ($_GET['action'] == 'pdf') if ($_GET['action'] == 'builddoc')
{ {
facture_pdf_create($db, $_GET['facid']); facture_pdf_create($db, $_GET['facid']);
} }
@@ -1616,11 +1616,11 @@ else
{ {
if ($fac->paye == 0) if ($fac->paye == 0)
{ {
print ' <a class="butAction" href="facture.php?facid='.$fac->id.'&amp;action=pdf">'.$langs->trans('BuildPDF').'</a>'; print ' <a class="butAction" href="facture.php?facid='.$fac->id.'&amp;action=builddoc">'.$langs->trans('BuildPDF').'</a>';
} }
else else
{ {
print ' <a class="butAction" href="facture.php?facid='.$fac->id.'&amp;action=pdf">'.$langs->trans('RebuildPDF').'</a>'; print ' <a class="butAction" href="facture.php?facid='.$fac->id.'&amp;action=builddoc">'.$langs->trans('RebuildPDF').'</a>';
} }
} }
} }

View File

@@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2005-2006 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
@@ -34,9 +34,9 @@
class Export class Export
{ {
var $array_export_code=array(); var $array_export_code=array(); // Tableau de "idmodule_numlot"
var $array_export_module=array(); var $array_export_module=array(); // Tableau de "nom de modules"
var $array_export_label=array(); var $array_export_label=array(); // Tableau de "libell<6C> de lots"
var $array_export_fields_code=array(); var $array_export_fields_code=array();
var $array_export_fields_label=array(); var $array_export_fields_label=array();
var $array_export_sql=array(); var $array_export_sql=array();
@@ -123,6 +123,71 @@ class Export
closedir($handle); closedir($handle);
} }
/**
* \brief Lance la generation du fichier
* \param user User qui exporte
* \param model Modele d'export
* \param datatoexport Lot de donn<6E>e <20> exporter
* \param array_selected Tableau des champs <20> exporter
* \remarks Les tableaux array_export_xxx sont d<>j<EFBFBD> charg<72>es pour le bon datatoexport
* aussi le parametre datatoexport est inutilis<69>
*/
function build_file($user, $model, $datatoexport, $array_selected)
{
global $conf,$langs;
$indice=0;
dolibarr_syslog("Export::build_file $model, $datatoexport, $array_selected");
// Creation de la classe d'export du model ExportXXX
$dir = DOL_DOCUMENT_ROOT . "/includes/modules/export/";
$file = "export_".$model.".modules.php";
$classname = "Export".$model;
require_once($dir.$file);
$obj = new $classname($db);
// Execute requete export
$sql=$this->array_export_sql[$indice];
$resql = $this->db->query($sql);
if ($resql)
{
//$this->array_export_label[$indice]
$filename="export_user".$user->id."_set".$datatoexport;
$filename.='.'.$obj->get_extension();
$dirname=$conf->export->dir_ouput;
// Open file
create_exdir($dirname);
$obj->open_file($dirname."/".$filename);
// Genere en-tete
$obj->write_header();
// Genere ligne de titre
$obj->write_title();
while ($objp = $this->db->fetch_object($resql))
{
$var=!$var;
$obj->write_record($objp,$array_selected);
}
// Genere en-tete
$obj->write_footer();
// Close file
$obj->close_file();
}
else
{
$this->error=$this->db->error();
dolibarr_syslog("Error: sql=$sql ".$this->error);
return -1;
}
}
} }
?> ?>

View File

@@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2005-2006 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
@@ -40,7 +40,7 @@ $array_selected=isset($_SESSION["export_selected_fields"])?$_SESSION["export_sel
$datatoexport=isset($_GET["datatoexport"])?$_GET["datatoexport"]:''; $datatoexport=isset($_GET["datatoexport"])?$_GET["datatoexport"]:'';
$export=new Export($db); $export=new Export($db);
$export->load_arrays($user,$datatoexport); $export->load_arrays($user,$datatoexport);
$action=isset($_GET["action"])?$_GET["action"]:''; $action=isset($_GET["action"]) ? $_GET["action"] : (isset($_POST["action"])?$_POST["action"]:'');
$step=isset($_GET["step"])?$_GET["step"]:'1'; $step=isset($_GET["step"])?$_GET["step"]:'1';
@@ -48,24 +48,72 @@ $step=isset($_GET["step"])?$_GET["step"]:'1';
/* /*
* Actions * Actions
*/ */
if ($action=='selectfield') if ($action=='selectfield')
{ {
$array_selected[$_GET["field"]]=1; $array_selected[$_GET["field"]]=sizeof($array_selected)+1;
//print_r($array_selected); //print_r($array_selected);
$_SESSION["export_selected_fields"]=$array_selected; $_SESSION["export_selected_fields"]=$array_selected;
} }
if ($action=='unselectfield') if ($action=='unselectfield')
{ {
$array_selected[$_GET["field"]]=0; unset($array_selected[$_GET["field"]]);
//print_r($array_selected); // Renumerote champs de array_selected (de 1 <20> nb_elements)
asort($array_selected);
$i=0;
$array_selected_save=$array_selected;
foreach($array_selected as $code=>$value)
{
$i++;
$array_selected[$code]=$i;
//print "x $code x $i y<br>";
}
$_SESSION["export_selected_fields"]=$array_selected; $_SESSION["export_selected_fields"]=$array_selected;
} }
if ($action=='downfield' || $action=='upfield')
{
$pos=$array_selected[$_GET["field"]];
if ($action=='downfield') $newpos=$pos+1;
if ($action=='upfield') $newpos=$pos-1;
// Recherche code avec qui switch<63>
$newcode="";
foreach($array_selected as $code=>$value)
{
if ($value == $newpos)
{
$newcode=$code;
break;
}
}
//print("Switch pos=$pos (code=".$_GET["field"].") and newpos=$newpos (code=$newcode)");
$array_selected[$_GET["field"]]=$newpos;
$array_selected[$newcode]=$pos;
$_SESSION["export_selected_fields"]=$array_selected;
}
if ($step == 1 || $action == 'cleanselect') if ($step == 1 || $action == 'cleanselect')
{ {
$_SESSION["export_selected_fields"]=array(); $_SESSION["export_selected_fields"]=array();
$array_selected=array(); $array_selected=array();
} }
if ($action == 'builddoc')
{
include_once(DOL_DOCUMENT_ROOT.'/includes/modules/export/modules_export.php');
$model=new ModeleExports();
$liste=$model->liste_modeles($db);
$model=$liste[$_POST["model"]];
// Gen<65>re le fichier
$export->build_file($user, $model, $datatoexport, $array_selected);
}
/*
* Affichage Pages des Etapes
*/
if ($step == 1 || ! $datatoexport) if ($step == 1 || ! $datatoexport)
{ {
@@ -224,6 +272,8 @@ if ($step == 2 && $datatoexport)
if ($step == 3 && $datatoexport) if ($step == 3 && $datatoexport)
{ {
asort($array_selected);
llxHeader('',$langs->trans("NewExport")); llxHeader('',$langs->trans("NewExport"));
/* /*
@@ -262,7 +312,7 @@ if ($step == 3 && $datatoexport)
// Nbre champs export<72>s // Nbre champs export<72>s
print '<tr><td width="25%">'.$langs->trans("ExportedFields").'</td>'; print '<tr><td width="25%">'.$langs->trans("ExportedFields").'</td>';
$list=''; $list='';
foreach($array_selected as $code=>$label) foreach($array_selected as $code=>$value)
{ {
$list.=($list?',':''); $list.=($list?',':'');
$list.=$langs->trans($export->array_export_fields[0][$code]); $list.=$langs->trans($export->array_export_fields[0][$code]);
@@ -276,7 +326,8 @@ if ($step == 3 && $datatoexport)
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td width="48%">'.$langs->trans("ExportedFields").'</td>'; print '<tr class="liste_titre"><td width="48%">'.$langs->trans("ExportedFields").'</td>';
print '<td>'.$langs->trans("Position").'</td>'; print '<td align="right" colspan="2">'.$langs->trans("Position").'</td>';
print '<td>&nbsp;</td>';
print '<td>'.$langs->trans("FieldsTitle").'</td>'; print '<td>'.$langs->trans("FieldsTitle").'</td>';
print '</tr>'; print '</tr>';
@@ -288,11 +339,15 @@ if ($step == 3 && $datatoexport)
print '<td>'.$langs->trans($export->array_export_fields[0][$code]).' ('.$code.')</td>'; print '<td>'.$langs->trans($export->array_export_fields[0][$code]).' ('.$code.')</td>';
print '<td>'; print '<td align="right" width="100">';
print '<a href="'.$_SERVER["PHP_SELF"].'?step=3&amp;datatoexport='.$datatoexport.'&amp;action=upfield&amp;field='.$field.'">'.img_up().'</a>'; print $value.' ';
print '<a href="'.$_SERVER["PHP_SELF"].'?step=3&amp;datatoexport='.$datatoexport.'&amp;action=downfield&amp;field='.$field.'">'.img_down().'</a>'; print '</td><td align="center" width="20">';
if ($value < sizeof($array_selected)) print '<a href="'.$_SERVER["PHP_SELF"].'?step=3&amp;datatoexport='.$datatoexport.'&amp;action=downfield&amp;field='.$code.'">'.img_down().'</a>';
if ($value > 1) print '<a href="'.$_SERVER["PHP_SELF"].'?step=3&amp;datatoexport='.$datatoexport.'&amp;action=upfield&amp;field='.$code.'">'.img_up().'</a>';
print '</td>'; print '</td>';
print '<td>&nbsp;</td>';
print '<td>'.$langs->trans($export->array_export_fields[0][$code]).'</td>'; print '<td>'.$langs->trans($export->array_export_fields[0][$code]).'</td>';
print '</tr>'; print '</tr>';
@@ -319,6 +374,8 @@ if ($step == 3 && $datatoexport)
if ($step == 4 && $datatoexport) if ($step == 4 && $datatoexport)
{ {
asort($array_selected);
llxHeader('',$langs->trans("NewExport")); llxHeader('',$langs->trans("NewExport"));
/* /*

View File

@@ -1842,7 +1842,7 @@ class Form
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print '<tr '.$bc[$var].'><td>'.$langs->trans('Model').'</td><td align="center">'; print '<tr '.$bc[$var].'><td>'.$langs->trans('Model').'</td><td align="center">';
$this->select_array('modelpdf',$liste,$modelselected); $this->select_array('model',$liste,$modelselected);
$texte=$langs->trans('Generate'); $texte=$langs->trans('Generate');
print '</td><td align="center" colspan="2"><input class="button" type="submit" value="'.$texte.'">'; print '</td><td align="center" colspan="2"><input class="button" type="submit" value="'.$texte.'">';
print '</td></tr>'; print '</td></tr>';

View File

@@ -0,0 +1,102 @@
<?php
/* Copyright (C) 2006 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* or see http://www.gnu.org/
*
* $Id$
* $Source$
*/
/**
\file htdocs/includes/modules/export/export_csv.modules.php
\ingroup export
\brief Fichier de la classe permettant de g<>n<EFBFBD>rer les export au format CSV
\author Laurent Destailleur
\version $Revision$
*/
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/export/modules_export.php");
/**
\class ExportCsv
\brief Classe permettant de g<>n<EFBFBD>rer les factures au mod<6F>le Crabe
*/
class ExportCsv extends ModeleExports
{
var $extension;
var $handle; // Handle fichier
/**
\brief Constructeur
\param db Handler acc<63>s base de donn<6E>e
*/
function ExportCsv($db)
{
global $conf,$langs;
$this->db = $db;
$this->extension='csv';
}
function get_extension()
{
return $this->extension;
}
function open_file($file)
{
dolibarr_syslog("ExportCsv::open_file file=$file");
$this->handle = fopen($file, "wt");
}
function write_header()
{
}
function write_title()
{
}
function write_record()
{
}
function write_footer()
{
}
function close_file()
{
fclose($this->handle);
}
}
?>

View File

@@ -29,8 +29,8 @@
/** /**
\class ModelePDFFactures \class ModeleExport
\brief Classe m<>re des mod<6F>les de facture \brief Classe m<>re des mod<6F>les de format d'export
*/ */
class ModeleExports class ModeleExports
@@ -88,6 +88,54 @@ class ModeleExports
return $this->driverversion[$key]; return $this->driverversion[$key];
} }
/**
* \brief Lance la generation du fichier
* \remarks Les tableaux array_export_xxx sont d<>j<EFBFBD> charg<72>es pour le bon datatoexport
* aussi le parametre datatoexport est inutilis<69>
*/
function build_file($model, $datatoexport, $array_selected)
{
global $langs;
dolibarr_syslog("Export::build_file $model, $datatoexport, $array_selected");
// Creation de la classe d'export du model ExportXXX
$dir = DOL_DOCUMENT_ROOT . "/includes/modules/export/";
$file = "export_".$model.".modules.php";
$classname = "Export".$model;
require_once($dir.$file);
$obj = new $classname($db);
// Execute requete export
$sql=$this->array_export_sql[0];
$resql = $this->db->query($sql);
if ($resql)
{
// Genere en-tete
$obj->write_header();
// Genere ligne de titre
$obj->write_title();
while ($objp = $this->db->fetch_object($resql))
{
$var=!$var;
$obj->write_record($objp,$array_selected);
}
// Genere en-tete
$obj->write_footer();
}
else
{
$this->error=$this->db->error();
dolibarr_syslog("Error: sql=$sql ".$this->error);
return -1;
}
}
} }