From 8b5005ba1630a3e667a48354a4bcc9fcde9cb040 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 21 Jan 2006 19:08:36 +0000 Subject: [PATCH] =?UTF-8?q?New:=20Possibilit=E9=20de=20choisir=20les=20ord?= =?UTF-8?q?res=20des=20champs=20dans=20les=20exports=20Debut=20de=20la=20g?= =?UTF-8?q?estion=20du=20format=20export=20csv.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/comm/addpropal.php | 2 +- htdocs/comm/propal.php | 8 +- htdocs/compta/facture.php | 8 +- htdocs/exports/export.class.php | 73 ++++++++++++- htdocs/exports/export.php | 77 +++++++++++-- htdocs/html.form.class.php | 2 +- .../modules/export/export_csv.modules.php | 102 ++++++++++++++++++ .../modules/export/modules_export.php | 52 ++++++++- 8 files changed, 298 insertions(+), 26 deletions(-) create mode 100644 htdocs/includes/modules/export/export_csv.modules.php diff --git a/htdocs/comm/addpropal.php b/htdocs/comm/addpropal.php index 753acc8801b..597632b0870 100644 --- a/htdocs/comm/addpropal.php +++ b/htdocs/comm/addpropal.php @@ -173,7 +173,7 @@ if ($_GET["action"] == 'create') print ''; $model=new ModelePDFPropales(); $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 ""; print '
'; diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 43ca9701e2c..70a7fe2ad3a 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -115,7 +115,7 @@ if ($_POST['action'] == 'add') $propal->contactid = $_POST['contactidp']; $propal->projetidp = $_POST['projetidp']; - $propal->modelpdf = $_POST['modelpdf']; + $propal->modelpdf = $_POST['model']; $propal->author = $user->id; $propal->note = $_POST['note']; @@ -136,7 +136,7 @@ if ($_POST['action'] == 'add') */ if ($id > 0) { - propale_pdf_create($db, $id, $_POST['modelpdf']); + propale_pdf_create($db, $id, $_POST['model']); Header ('Location: propal.php?propalid='.$id); exit; } @@ -331,8 +331,8 @@ if ($_POST['action'] == 'updateligne' && $user->rights->propale->creer && $_POST if ($_POST['action'] == 'builddoc' && $user->rights->propale->creer) { $propal = new Propal($db, 0, $_GET['propalid']); - $propal->set_pdf_model($user, $_POST['modelpdf']); - propale_pdf_create($db, $_GET['propalid'], $_POST['modelpdf']); + $propal->set_pdf_model($user, $_POST['model']); + propale_pdf_create($db, $_GET['propalid'], $_POST['model']); } diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index e1fb6a1c3f4..feb80e3aeb8 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -547,9 +547,9 @@ if ($_POST['action'] == 'send' || $_POST['action'] == 'relance') } /* - * Générer ou regénérer le PDF + * Générer ou regénérer le document PDF */ -if ($_GET['action'] == 'pdf') +if ($_GET['action'] == 'builddoc') { facture_pdf_create($db, $_GET['facid']); } @@ -1616,11 +1616,11 @@ else { if ($fac->paye == 0) { - print ' '.$langs->trans('BuildPDF').''; + print ' '.$langs->trans('BuildPDF').''; } else { - print ' '.$langs->trans('RebuildPDF').''; + print ' '.$langs->trans('RebuildPDF').''; } } } diff --git a/htdocs/exports/export.class.php b/htdocs/exports/export.class.php index 44295a77c48..4a06f228e74 100644 --- a/htdocs/exports/export.class.php +++ b/htdocs/exports/export.class.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2005-2006 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 @@ -34,9 +34,9 @@ class Export { - var $array_export_code=array(); - var $array_export_module=array(); - var $array_export_label=array(); + var $array_export_code=array(); // Tableau de "idmodule_numlot" + var $array_export_module=array(); // Tableau de "nom de modules" + var $array_export_label=array(); // Tableau de "libellé de lots" var $array_export_fields_code=array(); var $array_export_fields_label=array(); var $array_export_sql=array(); @@ -122,6 +122,71 @@ class Export } closedir($handle); } + + /** + * \brief Lance la generation du fichier + * \param user User qui exporte + * \param model Modele d'export + * \param datatoexport Lot de donnée à exporter + * \param array_selected Tableau des champs à exporter + * \remarks Les tableaux array_export_xxx sont déjà chargées pour le bon datatoexport + * aussi le parametre datatoexport est inutilisé + */ + 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; + } + } } diff --git a/htdocs/exports/export.php b/htdocs/exports/export.php index a443b2e7c90..8849e4aa584 100644 --- a/htdocs/exports/export.php +++ b/htdocs/exports/export.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2005-2006 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 @@ -40,7 +40,7 @@ $array_selected=isset($_SESSION["export_selected_fields"])?$_SESSION["export_sel $datatoexport=isset($_GET["datatoexport"])?$_GET["datatoexport"]:''; $export=new Export($db); $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'; @@ -48,24 +48,72 @@ $step=isset($_GET["step"])?$_GET["step"]:'1'; /* * Actions */ + if ($action=='selectfield') { - $array_selected[$_GET["field"]]=1; + $array_selected[$_GET["field"]]=sizeof($array_selected)+1; //print_r($array_selected); $_SESSION["export_selected_fields"]=$array_selected; } if ($action=='unselectfield') { - $array_selected[$_GET["field"]]=0; - //print_r($array_selected); + unset($array_selected[$_GET["field"]]); + // Renumerote champs de array_selected (de 1 à 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
"; + } $_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é + $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') { $_SESSION["export_selected_fields"]=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ère le fichier + $export->build_file($user, $model, $datatoexport, $array_selected); +} + + +/* + * Affichage Pages des Etapes + */ if ($step == 1 || ! $datatoexport) { @@ -224,6 +272,8 @@ if ($step == 2 && $datatoexport) if ($step == 3 && $datatoexport) { + asort($array_selected); + llxHeader('',$langs->trans("NewExport")); /* @@ -262,7 +312,7 @@ if ($step == 3 && $datatoexport) // Nbre champs exportés print ''.$langs->trans("ExportedFields").''; $list=''; - foreach($array_selected as $code=>$label) + foreach($array_selected as $code=>$value) { $list.=($list?',':''); $list.=$langs->trans($export->array_export_fields[0][$code]); @@ -276,7 +326,8 @@ if ($step == 3 && $datatoexport) print ''; print ''; - print ''; + print ''; + print ''; print ''; print ''; @@ -288,11 +339,15 @@ if ($step == 3 && $datatoexport) print ''; - print ''; + print ''; + print ''; print ''; @@ -319,6 +374,8 @@ if ($step == 3 && $datatoexport) if ($step == 4 && $datatoexport) { + asort($array_selected); + llxHeader('',$langs->trans("NewExport")); /* diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index e878c0fc7f0..ba72fa1faf4 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -1842,7 +1842,7 @@ class Form print '
'.$langs->trans("ExportedFields").''.$langs->trans("Position").''.$langs->trans("Position").' '.$langs->trans("FieldsTitle").'
'.$langs->trans($export->array_export_fields[0][$code]).' ('.$code.')'; - print ''.img_up().''; - print ''.img_down().''; + print ''; + print $value.' '; + print ''; + if ($value < sizeof($array_selected)) print ''.img_down().''; + if ($value > 1) print ''.img_up().''; print ' '.$langs->trans($export->array_export_fields[0][$code]).'
'; print ''; diff --git a/htdocs/includes/modules/export/export_csv.modules.php b/htdocs/includes/modules/export/export_csv.modules.php new file mode 100644 index 00000000000..9122b0afbeb --- /dev/null +++ b/htdocs/includes/modules/export/export_csv.modules.php @@ -0,0 +1,102 @@ + +* +* 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é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érer les factures au modèle Crabe +*/ + +class ExportCsv extends ModeleExports +{ + var $extension; + var $handle; // Handle fichier + + + /** + \brief Constructeur + \param db Handler accès base de donné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); + } + +} + +?> diff --git a/htdocs/includes/modules/export/modules_export.php b/htdocs/includes/modules/export/modules_export.php index 051baed8b6e..d732436995a 100644 --- a/htdocs/includes/modules/export/modules_export.php +++ b/htdocs/includes/modules/export/modules_export.php @@ -29,8 +29,8 @@ /** - \class ModelePDFFactures - \brief Classe mère des modèles de facture + \class ModeleExport + \brief Classe mère des modèles de format d'export */ class ModeleExports @@ -88,6 +88,54 @@ class ModeleExports return $this->driverversion[$key]; } + + + /** + * \brief Lance la generation du fichier + * \remarks Les tableaux array_export_xxx sont déjà chargées pour le bon datatoexport + * aussi le parametre datatoexport est inutilisé + */ + 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; + } + } + }
'.$langs->trans('Model').''; - $this->select_array('modelpdf',$liste,$modelselected); + $this->select_array('model',$liste,$modelselected); $texte=$langs->trans('Generate'); print ''; print '