From 4f43ec0acf03bc9e3347e21d42538212557f3ef1 Mon Sep 17 00:00:00 2001 From: Florian Henry Date: Mon, 10 Jun 2013 14:13:44 +0200 Subject: [PATCH] Add extrafield tables --- htdocs/core/class/extrafields.class.php | 91 +++++++++++++++++-- .../install/mysql/migration/3.4.0-3.5.0.sql | 30 ++++++ .../llx_commandedet_extrafields.key.sql | 24 +++++ .../tables/llx_commandedet_extrafields.sql | 25 +++++ .../tables/llx_facturedet_extrafields.key.sql | 20 ++++ .../tables/llx_facturedet_extrafields.sql | 25 +++++ .../tables/llx_propaldet_extrafields.key.sql | 20 ++++ .../tables/llx_propaldet_extrafields.sql | 25 +++++ 8 files changed, 253 insertions(+), 7 deletions(-) create mode 100755 htdocs/install/mysql/tables/llx_commandedet_extrafields.key.sql create mode 100755 htdocs/install/mysql/tables/llx_commandedet_extrafields.sql create mode 100755 htdocs/install/mysql/tables/llx_facturedet_extrafields.key.sql create mode 100755 htdocs/install/mysql/tables/llx_facturedet_extrafields.sql create mode 100755 htdocs/install/mysql/tables/llx_propaldet_extrafields.key.sql create mode 100755 htdocs/install/mysql/tables/llx_propaldet_extrafields.sql diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 8c5f485de32..5dc7c1c9755 100755 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -5,6 +5,7 @@ * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2009-2012 Laurent Destailleur * Copyright (C) 2009-2012 Regis Houssin +* Copyright (C) 2013 Florian Henry * * 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 @@ -559,7 +560,7 @@ class ExtraFields $this->attribute_pos[$tab->name]=$tab->pos; } } - + return $array_name_label; } else @@ -622,7 +623,7 @@ class ExtraFields $out = $formstat->select_date($value, 'options_'.$key, $showtime, $showtime, $required, '', 1, 1, 1, 0, 1); //$out=''; } - elseif (in_array($type,array('int','double'))) + elseif (in_array($type,array('int'))) { $tmp=explode(',',$size); $newsize=$tmp[0]; @@ -660,6 +661,13 @@ class ExtraFields { $out=' '.$langs->getCurrencySymbol($conf->currency); } + elseif ($type == 'double') + { + if (!empty($value)) { + $value=price($value); + } + $out=' '; + } elseif ($type == 'select') { $out=''; $param_list=array_keys($param['options']); $InfoFieldList = explode(":", $param_list[0]); - + // 0 1 : tableName // 1 2 : label field name Nom du champ contenant le libelle // 2 3 : key fields name (if differ of rowid) @@ -703,7 +711,13 @@ class ExtraFields while ($i < $num) { $obj = $this->db->fetch_object($resql); - $labeltoshow=dol_trunc($obj->$InfoFieldList[1],18); + $translabel=$langs->trans($obj->$InfoFieldList[1]); + if ($translabel!=$obj->$InfoFieldList[1]) { + $labeltoshow=dol_trunc($translabel,18); + }else { + $labeltoshow=dol_trunc($obj->$InfoFieldList[1],18); + } + if ($value==$obj->rowid) { $out.=''; @@ -790,6 +804,12 @@ class ExtraFields { $showsize=10; } + elseif ($type == 'double') + { + if (!empty($value)) { + $value=price($value); + } + } elseif ($type == 'boolean') { $checked=''; @@ -822,7 +842,7 @@ class ExtraFields if (count($InfoFieldList)==3) $keyList=$InfoFieldList[2]; - + $sql = 'SELECT '.$InfoFieldList[1]; $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; $sql.= ' WHERE '.$keyList.'=\''.$this->db->escape($value).'\''; @@ -832,7 +852,13 @@ class ExtraFields if ($resql) { $obj = $this->db->fetch_object($resql); - $value=$obj->$InfoFieldList[1]; + $translabel=$langs->trans($obj->$InfoFieldList[1]); + if ($translabel!=$obj->$InfoFieldList[1]) { + $value=dol_trunc($translabel,18); + }else { + $value=$obj->$InfoFieldList[1]; + } + } } elseif ($type == 'radio') @@ -882,7 +908,7 @@ class ExtraFields function setOptionalsFromPost($extralabels,&$object) { global $_POST; - + if (is_array($extralabels)) { // Get extra fields @@ -900,6 +926,11 @@ class ExtraFields $value_arr=GETPOST("options_".$key); $value_key=implode($value_arr,','); } + else if (in_array($key_type,array('price','double'))) + { + $value_arr=GETPOST("options_".$key); + $value_key=price2num($value_arr); + } else { $value_key=GETPOST("options_".$key); @@ -913,5 +944,51 @@ class ExtraFields return 0; } } + /** + * return array_options array for object by extrafields value (using for data send by forms) + * + * @param array $extralabels $array of extrafields + * @return int 1 if array_options set / 0 if no value + */ + function getOptionalsFromPost($extralabels) + { + global $_POST; + + $array_options = array(); + if (is_array($extralabels)) + { + // Get extra fields + foreach ($extralabels as $key => $value) + { + $key_type = $this->attribute_type[$key]; + + if (in_array($key_type,array('date','datetime'))) + { + // Clean parameters + $value_key=dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]); + } + else if (in_array($key_type,array('checkbox'))) + { + $value_arr=GETPOST("options_".$key); + $value_key=implode($value_arr,','); + } + else if (in_array($key_type,array('price','double'))) + { + $value_arr=GETPOST("options_".$key); + $value_key=price2num($value_arr); + } + else + { + $value_key=GETPOST("options_".$key); + } + $array_options["options_".$key]=$value_key; + } + + return $array_options; + } + else { + return 0; + } + } } ?> diff --git a/htdocs/install/mysql/migration/3.4.0-3.5.0.sql b/htdocs/install/mysql/migration/3.4.0-3.5.0.sql index 0fe73865793..01b9ac4af29 100755 --- a/htdocs/install/mysql/migration/3.4.0-3.5.0.sql +++ b/htdocs/install/mysql/migration/3.4.0-3.5.0.sql @@ -32,4 +32,34 @@ create table llx_fichinter_extrafields ALTER TABLE llx_fichinter_extrafields ADD INDEX idx_ficheinter_extrafields (fk_object); +create table llx_commandedet_extrafields +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + tms timestamp, + fk_object integer NOT NULL, + import_key varchar(14) +)ENGINE=innodb; + +ALTER TABLE llx_commandedet_extrafields ADD INDEX idx_commandedet_extrafields (fk_object); + +create table llx_facturedet_extrafields +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + tms timestamp, + fk_object integer NOT NULL, -- object id + import_key varchar(14) -- import key +)ENGINE=innodb; + +ALTER TABLE llx_facturedet_extrafields ADD INDEX idx_facturedet_extrafields (fk_object); + +create table llx_propaldet_extrafields +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + tms timestamp, + fk_object integer NOT NULL, -- object id + import_key varchar(14) -- import key +)ENGINE=innodb; + +ALTER TABLE llx_propaldet_extrafields ADD INDEX idx_propaldet_extrafields (fk_object); + diff --git a/htdocs/install/mysql/tables/llx_commandedet_extrafields.key.sql b/htdocs/install/mysql/tables/llx_commandedet_extrafields.key.sql new file mode 100755 index 00000000000..764b39639cf --- /dev/null +++ b/htdocs/install/mysql/tables/llx_commandedet_extrafields.key.sql @@ -0,0 +1,24 @@ +-- =================================================================== +-- Copyright (C) 2002-2003 Rodolphe Quiedeville +-- Copyright (C) 2002-2003 Jean-Louis Bergamo +-- Copyright (C) 2009 Regis Houssin +-- Copyright (C) 2011 Laurent Destailleur +-- Copyright (C) 2013 Florian Henry +-- +-- 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 3 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, see . +-- +-- =================================================================== + + +ALTER TABLE llx_commandedet_extrafields ADD INDEX idx_commandedet_extrafields (fk_object); diff --git a/htdocs/install/mysql/tables/llx_commandedet_extrafields.sql b/htdocs/install/mysql/tables/llx_commandedet_extrafields.sql new file mode 100755 index 00000000000..24e59f9d9b5 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_commandedet_extrafields.sql @@ -0,0 +1,25 @@ +-- =================================================================== +-- Copyright (C) 2013 Florian Henry +-- +-- 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 3 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, see . +-- +-- =================================================================== + +create table llx_commandedet_extrafields +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + tms timestamp, + fk_object integer NOT NULL, -- object id + import_key varchar(14) -- import key +)ENGINE=innodb; diff --git a/htdocs/install/mysql/tables/llx_facturedet_extrafields.key.sql b/htdocs/install/mysql/tables/llx_facturedet_extrafields.key.sql new file mode 100755 index 00000000000..6334f84f81c --- /dev/null +++ b/htdocs/install/mysql/tables/llx_facturedet_extrafields.key.sql @@ -0,0 +1,20 @@ +-- =================================================================== +-- Copyright (C) 2013 Florian Henry +-- +-- 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 3 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, see . +-- +-- =================================================================== + + +ALTER TABLE llx_facturedet_extrafields ADD INDEX idx_facturedet_extrafields (fk_object); diff --git a/htdocs/install/mysql/tables/llx_facturedet_extrafields.sql b/htdocs/install/mysql/tables/llx_facturedet_extrafields.sql new file mode 100755 index 00000000000..0bd90804a1f --- /dev/null +++ b/htdocs/install/mysql/tables/llx_facturedet_extrafields.sql @@ -0,0 +1,25 @@ +-- =================================================================== +-- Copyright (C) 2013 Florian Henry +-- +-- 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 3 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, see . +-- +-- =================================================================== + +create table llx_facturedet_extrafields +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + tms timestamp, + fk_object integer NOT NULL, -- object id + import_key varchar(14) -- import key +)ENGINE=innodb; diff --git a/htdocs/install/mysql/tables/llx_propaldet_extrafields.key.sql b/htdocs/install/mysql/tables/llx_propaldet_extrafields.key.sql new file mode 100755 index 00000000000..0014a20d81d --- /dev/null +++ b/htdocs/install/mysql/tables/llx_propaldet_extrafields.key.sql @@ -0,0 +1,20 @@ +-- =================================================================== +-- Copyright (C) 2013 Florian Henry +-- +-- 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 3 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, see . +-- +-- =================================================================== + + +ALTER TABLE llx_propaldet_extrafields ADD INDEX idx_propaldet_extrafields (fk_object); diff --git a/htdocs/install/mysql/tables/llx_propaldet_extrafields.sql b/htdocs/install/mysql/tables/llx_propaldet_extrafields.sql new file mode 100755 index 00000000000..58883a84dbe --- /dev/null +++ b/htdocs/install/mysql/tables/llx_propaldet_extrafields.sql @@ -0,0 +1,25 @@ +-- =================================================================== +-- Copyright (C) 2013 Florian Henry +-- +-- 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 3 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, see . +-- +-- =================================================================== + +create table llx_propaldet_extrafields +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + tms timestamp, + fk_object integer NOT NULL, -- object id + import_key varchar(14) -- import key +)ENGINE=innodb;