From 6761e14a9d38f2634a147d9b0bda17c62f7192e5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 25 Oct 2008 15:53:16 +0000 Subject: [PATCH] Qual: Mutualize some code --- htdocs/html.form.class.php | 20 ++--- htdocs/html.formproduct.class.php | 123 ++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+), 10 deletions(-) create mode 100644 htdocs/html.formproduct.class.php diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index fa9801d754f..10e4f6d56f9 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -2937,16 +2937,16 @@ class Form /** - \brief Affiche un select à partir d'un tableau - \param htmlname Nom de la zone select - \param array Tableau de key+valeur - \param id Preselected key - \param show_empty 1 si il faut ajouter une valeur vide dans la liste, 0 sinon - \param key_in_label 1 pour afficher la key dans la valeur "[key] value" - \param value_as_key 1 pour utiliser la valeur comme clé - \param optionType Type de l'option: 1 pour des fonctions javascript - \param option Valeur de l'option en fonction du type choisi - \param translate Traduire la valeur + * \brief Show a select form from an array + * \param htmlname Nom de la zone select + * \param array Tableau de key+valeur + * \param id Preselected key + * \param show_empty 1 si il faut ajouter une valeur vide dans la liste, 0 sinon + * \param key_in_label 1 pour afficher la key dans la valeur "[key] value" + * \param value_as_key 1 pour utiliser la valeur comme clé + * \param optionType Type de l'option: 1 pour des fonctions javascript + * \param option Valeur de l'option en fonction du type choisi + * \param translate Traduire la valeur */ function select_array($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $optionType=0, $option='', $translate=0) { diff --git a/htdocs/html.formproduct.class.php b/htdocs/html.formproduct.class.php new file mode 100644 index 00000000000..73bfbc49076 --- /dev/null +++ b/htdocs/html.formproduct.class.php @@ -0,0 +1,123 @@ + + * + * 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. + */ + +/** + * \file htdocs/html.formproduct.class.php + * \brief Fichier de la classe des fonctions prédéfinie de composants html + * \version $Id$ + */ + + +/** + * \class FormProduct + * \brief Classe permettant la génération de composants html + * \remarks Only common components must be here. + */ +class FormProduct +{ + var $db; + var $error; + + // Cache arrays + var $cache_warehouses=array(); + + var $tva_taux_value; + var $tva_taux_libelle; + + + /** + \brief Constructeur + \param DB handler d'accès base de donnée + */ + function FormProduct($DB) + { + $this->db = $DB; + + return 1; + } + + + /** + * \brief Load in cache array list of warehouses + * \return int Nb of loaded lines, 0 if already loaded, <0 if KO + */ + function loadWarehouses() + { + global $langs; + + if (sizeof($this->cache_warehouses)) return 0; // Cache already loaded + + $sql = "SELECT e.rowid, e.label FROM ".MAIN_DB_PREFIX."entrepot as e"; + $sql .= " WHERE statut = 1"; + $sql .= " ORDER BY e.label"; + + dolibarr_syslog('FormProduct::loadWarehouses sql='.$sql,LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); + $i = 0; + while ($i < $num) + { + $obj = $this->db->fetch_object($resql); + + $this->cache_warehouses[$obj->rowid]['id'] =$obj->rowid; + $this->cache_warehouses[$obj->rowid]['label']=$obj->label; + $i++; + } + return $num; + } + else + { + dolibarr_print_error($this->db); + return -1; + } + } + + /** + * \brief Retourne la liste des modes de paiements possibles + * \param selected Id du mode de paiement pré-sélectionné + * \param htmlname Nom de la zone select + * \param filtertype Pour filtre + * \param empty 1=peut etre vide, 0 sinon + */ + function selectWarehouses($selected='',$htmlname='idwarehouse',$filtertype='',$empty=0) + { + global $langs,$user; + + dolibarr_syslog("Form::selectWarehouses $selected, $htmlname, $filtertype, $format",LOG_DEBUG); + + $this->loadWarehouses(); + + print ''; + } + +} + +?>