From 9b966925e8088450fadf935a52c801b0286bf937 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 23 Mar 2007 17:58:06 +0000 Subject: [PATCH] =?UTF-8?q?Ajout=20possibilit=E9=20d'enregistrer=20des=20m?= =?UTF-8?q?od=E8les=20d'exports=20afin=20de=20ne=20pas=20les=20selectionne?= =?UTF-8?q?r=20=E0=20chaque=20fois,=20fonctionnalit=E9=20op=E9rationnel=20?= =?UTF-8?q?mais=20reste=20=E0=20la=20fignoler=20!!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/exports/export.class.php | 75 +++++++++++++++++++++++++++ htdocs/exports/export.php | 69 ++++++++++++++++++++++-- htdocs/html.form.class.php | 47 +++++++++++++++++ htdocs/lib/functions.inc.php | 28 ++++++++++ mysql/migration/2.0.0-2.1.0.sql | 12 ++++- mysql/tables/llx_export_model.key.sql | 25 +++++++++ mysql/tables/llx_export_model.sql | 32 ++++++++++++ 7 files changed, 283 insertions(+), 5 deletions(-) create mode 100644 mysql/tables/llx_export_model.key.sql create mode 100644 mysql/tables/llx_export_model.sql diff --git a/htdocs/exports/export.class.php b/htdocs/exports/export.class.php index ef197c5278f..b500e51f93c 100644 --- a/htdocs/exports/export.class.php +++ b/htdocs/exports/export.class.php @@ -41,6 +41,11 @@ class Export var $array_export_fields=array(); // Tableau des liste de champ+libellé à exporter var $array_export_alias=array(); // Tableau des liste de champ+alias à exporter + // Création des modéles d'export + var $hexa; + var $datatoexport; + var $model_name; + /** * \brief Constructeur de la classe @@ -205,6 +210,76 @@ class Export } } + /** + * \brief Créé un modéle d'export + * \param user Objet utilisateur qui crée + */ + function create($user) + { + global $conf; + + dolibarr_syslog("Export.class.php::create"); + + $this->db->begin(); + + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'export_model ('; + $sql.= 'nom, type, field)'; + $sql.= " VALUES ('".$this->model_name."', '".$this->datatoexport."', '".$this->hexa."')"; + + dolibarr_syslog("Export.class.php::create sql=".$sql); + + $resql=$this->db->query($sql); + if ($resql) + { + $this->db->commit(); + return 1; + } + else + { + dolibarr_print_error($this->db); + $this->db->rollback(); + return -1; + } + } + + /** + * \brief Recupère de la base les caractéristiques d'un modele d'export + * \param rowid id du modéle à récupérer + */ + function fetch($id) + { + $sql = 'SELECT em.rowid, em.field, em.nom, em.type'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'export_model as em'; + $sql.= ' WHERE em.rowid = '.$id; + + dolibarr_syslog("Export::fetch sql=$sql"); + + $result = $this->db->query($sql) ; + if ($result) + { + $obj = $this->db->fetch_object($result); + if ($obj) + { + $this->id = $obj->rowid; + $this->hexa = $obj->field; + $this->model_name = $obj->nom; + $this->datatoexport = $obj->type; + + return 1; + } + else + { + $this->error="Model not found"; + return -2; + } + } + else + { + dolibarr_print_error($this->db); + return -3; + } + } + } ?> diff --git a/htdocs/exports/export.php b/htdocs/exports/export.php index 2d7986feec7..49653d53ae6 100644 --- a/htdocs/exports/export.php +++ b/htdocs/exports/export.php @@ -51,14 +51,18 @@ $entitytolang=array( 'member'=>'Member','member_type'=>'MemberType'); $array_selected=isset($_SESSION["export_selected_fields"])?$_SESSION["export_selected_fields"]:array(); -$datatoexport=isset($_GET["datatoexport"])?$_GET["datatoexport"]:''; +$datatoexport=isset($_GET["datatoexport"])? $_GET["datatoexport"] : (isset($_POST["datatoexport"])?$_POST["datatoexport"]:''); $action=isset($_GET["action"]) ? $_GET["action"] : (isset($_POST["action"])?$_POST["action"]:''); -$step=isset($_GET["step"])?$_GET["step"]:'1'; +$step=isset($_GET["step"])? $_GET["step"] : (isset($_POST["step"])?$_POST["step"]:1); +$export_name=isset($_POST["export_name"])? $_POST["export_name"] : ''; +$hexa=isset($_POST["hexa"])? $_POST["hexa"] : ''; +$exportmodelid=isset($_POST["exportmodelid"])? $_POST["exportmodelid"] : ''; $objexport=new Export($db); $objexport->load_arrays($user,$datatoexport); $objmodelexport=new ModeleExports(); +$html = new Form($db); /* @@ -131,6 +135,26 @@ if ($action == 'builddoc') } } +if ($step == 2 && $action == 'add') +{ + $objexport->model_name = $export_name; + $objexport->datatoexport = $datatoexport; + $objexport->hexa = $hexa; + + $result = $objexport->create($user); +} + +if ($step == 2 && $action == 'select_model') +{ + $_SESSION["export_selected_fields"]=array(); + $array_selected=array(); + $result = $objexport->fetch($exportmodelid); + if ($result > 0) + { + $binaire = hexbin($objexport->hexa); + } +} + /* * Affichage Pages des Etapes @@ -229,6 +253,18 @@ if ($step == 2 && $datatoexport) // Lot de données à exporter print ''.$langs->trans("DatasetToExport").''; print ''.$objexport->array_export_label[0].''; + + // Liste déroulante des modéles d'export + print ''.$langs->trans("ExportModel").''; + print '
'; + print ''; + print ''; + print ''; + print ''; + $html->select_export_model($exportmodelid,'exportmodelid',$datatoexport,1); + print ''; + print '
'; + print ''; print '
'; @@ -255,22 +291,34 @@ if ($step == 2 && $datatoexport) # $this->array_export_alias[0]=$module->export_fields_alias[$r]; $var=true; + $i = 0; + foreach($fieldsarray as $code=>$label) { $var=!$var; print ""; + + $modelchoice = substr($binaire,$i,1); + $i++; $entity=$objexport->array_export_entities[0][$code]; $entityicon=$entitytoicon[$entity]?$entitytoicon[$entity]:$entity; $entitylang=$entitytolang[$entity]?$entitytolang[$entity]:$entity; print ''.img_object('',$entityicon).' '.$langs->trans($entitylang).''; - if (isset($array_selected[$code]) && $array_selected[$code]) + if (isset($array_selected[$code]) && $array_selected[$code] || $modelchoice == 1) { // Champ sélectionné print ' '; print ''.img_left().''; print ''.$langs->trans($label).' ('.$code.')'; + if ($modelchoice == 1) + { + $array_selected[$code]=sizeof($array_selected)+1; + $_SESSION["export_selected_fields"]=$array_selected; + } + + $bit=1; } else { @@ -278,11 +326,13 @@ if ($step == 2 && $datatoexport) print ''.$langs->trans($label).' ('.$code.')'; print ''.img_right().''; print ' '; + $bit=0; } print ''; + $save_select.=$bit; } - + print ''; print ''; @@ -295,7 +345,18 @@ if ($step == 2 && $datatoexport) if (sizeof($array_selected)) { + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print '
'; + print ''; + print ''; print ''.$langs->trans("NextStep").''; + print '
'; } print ''; diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index 1bd690ad830..f18bc224e18 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -2923,6 +2923,53 @@ class Form return 1; } + /** + * \brief Retourne la liste des modéles d'export + * \param selected Id modéle présélectionné + * \param htmlname Nom de la zone select + * \param type Type des modéles recherchés + * \param useempty Affiche valeur vide dans liste + */ + function select_export_model($selected='',$htmlname='exportmodelid',$type='',$useempty=0) + { + + $sql = "SELECT rowid, nom"; + $sql.= " FROM ".MAIN_DB_PREFIX."export_model"; + $sql.= " WHERE type = '".$type."'"; + $sql.= " ORDER BY rowid"; + $result = $this->db->query($sql); + if ($result) + { + print '"; + } + else { + dolibarr_print_error($this->db); + } + } + } ?> diff --git a/htdocs/lib/functions.inc.php b/htdocs/lib/functions.inc.php index 19fb1e29777..a8da7e5d35b 100644 --- a/htdocs/lib/functions.inc.php +++ b/htdocs/lib/functions.inc.php @@ -2329,4 +2329,32 @@ function clean_html($StringHtml) return $CleanString; } +/** + \brief Convertir de l'héxadécimal en binaire + \param string bin + \return string x +*/ +function binhex($bin, $pad=false, $upper=false){ + $last = strlen($bin)-1; + for($i=0; $i<=$last; $i++){ $x += $bin[$last-$i] * pow(2,$i); } + $x = dechex($x); + if($pad){ while(strlen($x) < intval(strlen($bin))/4){ $x = "0$x"; } } + if($upper){ $x = strtoupper($x); } + return $x; +} + +/** + \brief Convertir de l'héxadécimal en binaire + \param string hexa + \return string bin +*/ +function hexbin($hexa){ + $bin=''; + for($i=0;$i diff --git a/mysql/migration/2.0.0-2.1.0.sql b/mysql/migration/2.0.0-2.1.0.sql index bd6c01f053a..2f07d0511c6 100644 --- a/mysql/migration/2.0.0-2.1.0.sql +++ b/mysql/migration/2.0.0-2.1.0.sql @@ -904,4 +904,14 @@ ALTER TABLE llx_document_model ADD UNIQUE uk_document_model (nom,type); ALTER TABLE llx_chargesociales drop column date_pai; -UPDATE llx_facture SET type=0 where type=3; \ No newline at end of file +UPDATE llx_facture SET type=0 where type=3; + +create table llx_export_model +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + label varchar(50) NOT NULL, + type varchar(20) NOT NULL, + field varchar(20) NOT NULL +)type=innodb; + +ALTER TABLE llx_export_model ADD UNIQUE uk_export_model (label); \ No newline at end of file diff --git a/mysql/tables/llx_export_model.key.sql b/mysql/tables/llx_export_model.key.sql new file mode 100644 index 00000000000..a031f97c13a --- /dev/null +++ b/mysql/tables/llx_export_model.key.sql @@ -0,0 +1,25 @@ +-- =================================================================== +-- Copyright (C) 2007 Laurent Destailleur +-- Copyright (C) 2007 Regis Houssin +-- +-- 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. +-- +-- $Id$ +-- $Source$ +-- +-- =================================================================== + + +ALTER TABLE llx_export_model ADD UNIQUE uk_export_model (label); \ No newline at end of file diff --git a/mysql/tables/llx_export_model.sql b/mysql/tables/llx_export_model.sql new file mode 100644 index 00000000000..46f23c47324 --- /dev/null +++ b/mysql/tables/llx_export_model.sql @@ -0,0 +1,32 @@ +-- =================================================================== +-- Copyright (C) 2001-2003 Rodolphe Quiedeville +-- Copyright (C) 2007 Regis Houssin +-- +-- 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. +-- +-- $Id$ +-- $Source$ +-- +-- Liste des modeles de document disponibles +-- +-- =================================================================== + +create table llx_export_model +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + label varchar(50) NOT NULL, + type varchar(20) NOT NULL, + field varchar(20) NOT NULL +)type=innodb; \ No newline at end of file