Add extrafield tables

This commit is contained in:
Florian Henry 2013-06-10 14:13:44 +02:00
parent 53f512b7dc
commit 4f43ec0acf
8 changed files with 253 additions and 7 deletions

View File

@ -5,6 +5,7 @@
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2009-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2009-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2013 Florian Henry <forian.henry@open-concept.pro>
*
* 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='<input type="text" name="options_'.$key.'" size="'.$showsize.'" maxlength="'.$newsize.'" value="'.$value.'"'.($moreparam?$moreparam:'').'>';
}
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='<input type="text" name="options_'.$key.'" size="6" value="'.price($value).'"> '.$langs->getCurrencySymbol($conf->currency);
}
elseif ($type == 'double')
{
if (!empty($value)) {
$value=price($value);
}
$out='<input type="text" name="options_'.$key.'" size="6" value="'.$value.'"> ';
}
elseif ($type == 'select')
{
$out='<select name="options_'.$key.'">';
@ -676,7 +684,7 @@ class ExtraFields
$out='<select name="options_'.$key.'">';
$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.='<option value="'.$obj->rowid.'" selected="selected">'.$labeltoshow.'</option>';
@ -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;
}
}
}
?>

View File

@ -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);

View File

@ -0,0 +1,24 @@
-- ===================================================================
-- Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
-- Copyright (C) 2009 Regis Houssin <regis.houssin@capnetworks.com>
-- Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net>
-- Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
--
-- 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 <http://www.gnu.org/licenses/>.
--
-- ===================================================================
ALTER TABLE llx_commandedet_extrafields ADD INDEX idx_commandedet_extrafields (fk_object);

View File

@ -0,0 +1,25 @@
-- ===================================================================
-- Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
--
-- 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 <http://www.gnu.org/licenses/>.
--
-- ===================================================================
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;

View File

@ -0,0 +1,20 @@
-- ===================================================================
-- Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
--
-- 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 <http://www.gnu.org/licenses/>.
--
-- ===================================================================
ALTER TABLE llx_facturedet_extrafields ADD INDEX idx_facturedet_extrafields (fk_object);

View File

@ -0,0 +1,25 @@
-- ===================================================================
-- Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
--
-- 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 <http://www.gnu.org/licenses/>.
--
-- ===================================================================
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;

View File

@ -0,0 +1,20 @@
-- ===================================================================
-- Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
--
-- 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 <http://www.gnu.org/licenses/>.
--
-- ===================================================================
ALTER TABLE llx_propaldet_extrafields ADD INDEX idx_propaldet_extrafields (fk_object);

View File

@ -0,0 +1,25 @@
-- ===================================================================
-- Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
--
-- 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 <http://www.gnu.org/licenses/>.
--
-- ===================================================================
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;