New: Extra fields supports more types (now int, string, double, date,

datetime)
This commit is contained in:
Laurent Destailleur 2012-09-13 10:14:25 +02:00
parent 29b4e1f57a
commit 4cc56f0176
10 changed files with 84 additions and 43 deletions

View File

@ -28,6 +28,7 @@ For users:
- New: Add link to third party into sells and purchase journal. - New: Add link to third party into sells and purchase journal.
- New: Suggest a method to generate a backup file for user with no access - New: Suggest a method to generate a backup file for user with no access
to mysqldump binary. to mysqldump binary.
- New: Extra fields supports more types (now int, string, double, date, datetime).
- New: Can correct stock of a warehouse from warehouse card. - New: Can correct stock of a warehouse from warehouse card.
- New: [ task #185 ]: Can input amount when correcting stock to recalculate PMP. - New: [ task #185 ]: Can input amount when correcting stock to recalculate PMP.
- New: [ task #454 ]: Add "No category" into filters on category. - New: [ task #454 ]: Add "No category" into filters on category.
@ -35,16 +36,16 @@ For users:
- New: More surface control on stock correction page. - New: More surface control on stock correction page.
- New: Add great britain provinces. - New: Add great britain provinces.
- New: Update libs/tools/logo for DoliWamp. - New: Update libs/tools/logo for DoliWamp.
- New: [ task #494 ] Send an email to foundation when a new member has auto-subscribed - New: [ task #494 ] Send an email to foundation when a new member has auto-subscribed.
- New: [ task #326 ]: Add a numbering module to suggest automatically a product ref - New: [ task #326 ]: Add a numbering module to suggest automatically a product ref.
- New: Add conditional substitution IF/ELSEIF/ENDIF for ODT templates - New: Add conditional substitution IF/ELSEIF/ENDIF for ODT templates.
- New: Add unit foot2, inch2, foot3 and inch3 for surface and volumes. - New: Add unit foot2, inch2, foot3 and inch3 for surface and volumes.
- New: Can select thirdparties into emailing targets, even if module category is not enabled. - New: Can select thirdparties into emailing targets, even if module category is not enabled.
- New: [ task #498 ] Improvement of the block to add products/services lines. - New: [ task #498 ] Improvement of the block to add products/services lines.
- New: ECM autodir works also for files joined to products and services. - New: ECM autodir works also for files joined to products and services.
- New: Add a selection module for emailing to enter a recipient from gui. - New: Add a selection module for emailing to enter a recipient from gui.
- New: Allow to search thirds and products from barcodes directly from the permanent mini search left box - New: Allow to search thirds and products from barcodes directly from the permanent mini search left box.
- New: Allow to search product from barcodes directly from invoices, proposals... through AJAX - New: Allow to search product from barcodes directly from invoices, proposals... through AJAX.
New experimental modules: New experimental modules:
- New: Add margin and commissions management module. - New: Add margin and commissions management module.
- New: Add holiday module. - New: Add holiday module.

View File

@ -34,13 +34,9 @@ $extrafields = new ExtraFields($db);
$form = new Form($db); $form = new Form($db);
// List of supported format // List of supported format
$type2label=array( $tmptype2label=getStaticMember(get_class($extrafields),'type2label');
'varchar'=>$langs->trans('String'), $type2label=array('');
'text'=>$langs->trans('Text'), foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->trans($val);
'int'=>$langs->trans('Int'),
'date'=>$langs->trans('Date'),
'datetime'=>$langs->trans('DateAndTime')
);
$action=GETPOST("action"); $action=GETPOST("action");
$elementtype='member'; $elementtype='member';

View File

@ -24,20 +24,34 @@
$maxsizestring=255; $maxsizestring=255;
$maxsizeint=10; $maxsizeint=10;
$extrasize=GETPOST('size');
if (GETPOST('type')=='double' && strpos($extrasize,',')===false) $extrasize='24,8';
if (GETPOST('type')=='date') $extrasize='';
if (GETPOST('type')=='datetime') $extrasize='';
// Add attribute // Add attribute
if ($action == 'add') if ($action == 'add')
{ {
if ($_POST["button"] != $langs->trans("Cancel")) if ($_POST["button"] != $langs->trans("Cancel"))
{ {
// Check values // Check values
if (GETPOST('type')=='varchar' && GETPOST('size') > $maxsizestring) if (! GETPOST('type'))
{
$error++;
$langs->load("errors");
$mesg=$langs->trans("ErrorFieldRequired",$langs->trans("Type"));
$action = 'create';
}
if (GETPOST('type')=='varchar' && $extrasize > $maxsizestring)
{ {
$error++; $error++;
$langs->load("errors"); $langs->load("errors");
$mesg=$langs->trans("ErrorSizeTooLongForVarcharType",$maxsizestring); $mesg=$langs->trans("ErrorSizeTooLongForVarcharType",$maxsizestring);
$action = 'create'; $action = 'create';
} }
if (GETPOST('type')=='int' && GETPOST('size') > $maxsizeint) if (GETPOST('type')=='int' && $extrasize > $maxsizeint)
{ {
$error++; $error++;
$langs->load("errors"); $langs->load("errors");
@ -50,7 +64,7 @@ if ($action == 'add')
// Type et taille non encore pris en compte => varchar(255) // Type et taille non encore pris en compte => varchar(255)
if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_POST['attrname'])) if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_POST['attrname']))
{ {
$result=$extrafields->addExtraField($_POST['attrname'],$_POST['label'],$_POST['type'],$_POST['pos'],$_POST['size'],$elementtype); $result=$extrafields->addExtraField($_POST['attrname'],$_POST['label'],$_POST['type'],$_POST['pos'],$extrasize,$elementtype);
if ($result > 0) if ($result > 0)
{ {
header("Location: ".$_SERVER["PHP_SELF"]); header("Location: ".$_SERVER["PHP_SELF"]);
@ -79,14 +93,21 @@ if ($action == 'update')
if ($_POST["button"] != $langs->trans("Cancel")) if ($_POST["button"] != $langs->trans("Cancel"))
{ {
// Check values // Check values
if (GETPOST('type')=='varchar' && GETPOST('size') > $maxsizestring) if (! GETPOST('type'))
{
$error++;
$langs->load("errors");
$mesg=$langs->trans("ErrorFieldRequired",$langs->trans("Type"));
$action = 'create';
}
if (GETPOST('type')=='varchar' && $extrasize > $maxsizestring)
{ {
$error++; $error++;
$langs->load("errors"); $langs->load("errors");
$mesg=$langs->trans("ErrorSizeTooLongForVarcharType",$maxsizestring); $mesg=$langs->trans("ErrorSizeTooLongForVarcharType",$maxsizestring);
$action = 'edit'; $action = 'edit';
} }
if (GETPOST('type')=='int' && GETPOST('size') > $maxsizeint) if (GETPOST('type')=='int' && $extrasize > $maxsizeint)
{ {
$error++; $error++;
$langs->load("errors"); $langs->load("errors");
@ -98,12 +119,12 @@ if ($action == 'update')
{ {
if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_POST['attrname'])) if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_POST['attrname']))
{ {
$result=$extrafields->update($_POST['attrname'],$_POST['type'],$_POST['size'],$elementtype); $result=$extrafields->update($_POST['attrname'],$_POST['type'],$extrasize,$elementtype);
if ($result > 0) if ($result > 0)
{ {
if (isset($_POST['label'])) if (isset($_POST['label']))
{ {
$extrafields->update_label($_POST['attrname'],$_POST['label'],$_POST['type'],$_POST['size'],$elementtype); $extrafields->update_label($_POST['attrname'],$_POST['label'],$_POST['type'],$extrasize,$elementtype);
} }
header("Location: ".$_SERVER["PHP_SELF"]); header("Location: ".$_SERVER["PHP_SELF"]);
exit; exit;

View File

@ -3,7 +3,7 @@
* Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org> * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org> * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be> * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2009-2011 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2009-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2009-2011 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2009-2011 Regis Houssin <regis@dolibarr.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -42,6 +42,14 @@ class ExtraFields
var $error; var $error;
var $errno; var $errno;
static $type2label=array(
'varchar'=>'String',
'text'=>'TextLong',
'int'=>'Int',
'double'=>'Float',
'date'=>'Date',
'datetime'=>'DateAndTime'
);
/** /**
* Constructor * Constructor
@ -74,10 +82,12 @@ class ExtraFields
if (empty($attrname)) return -1; if (empty($attrname)) return -1;
if (empty($label)) return -1; if (empty($label)) return -1;
// Create field into database
$result=$this->create($attrname,$type,$size,$elementtype); $result=$this->create($attrname,$type,$size,$elementtype);
$err1=$this->errno; $err1=$this->errno;
if ($result > 0 || $err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS') if ($result > 0 || $err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS')
{ {
// Add declaration of field into table
$result2=$this->create_label($attrname,$label,$type,$pos,$size,$elementtype); $result2=$this->create_label($attrname,$label,$type,$pos,$size,$elementtype);
$err2=$this->errno; $err2=$this->errno;
if ($result2 > 0 || ($err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' && $err2 == 'DB_ERROR_RECORD_ALREADY_EXISTS')) if ($result2 > 0 || ($err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' && $err2 == 'DB_ERROR_RECORD_ALREADY_EXISTS'))
@ -142,7 +152,7 @@ class ExtraFields
* *
* @param string $attrname code of attribute * @param string $attrname code of attribute
* @param string $label label of attribute * @param string $label label of attribute
* @param int $type Type of attribute ('int', 'text', 'varchar', 'date', 'datehour') * @param int $type Type of attribute ('int', 'text', 'varchar', 'date', 'datehour', 'float')
* @param int $pos Position of attribute * @param int $pos Position of attribute
* @param int $size Size/length of attribute * @param int $size Size/length of attribute
* @param string $elementtype Element type ('member', 'product', 'company', ...) * @param string $elementtype Element type ('member', 'product', 'company', ...)
@ -444,7 +454,7 @@ class ExtraFields
{ {
$showsize=19; $showsize=19;
} }
elseif ($type == 'int') elseif (in_array($type,array('int','double')))
{ {
$showsize=10; $showsize=10;
} }
@ -454,9 +464,17 @@ class ExtraFields
if ($showsize > 48) $showsize=48; if ($showsize > 48) $showsize=48;
} }
if ($type == 'int') if (in_array($type,array('date','datetime')))
{ {
$out='<input type="text" name="options_'.$key.'" size="'.$showsize.'" maxlength="'.$size.'" value="'.$value.'"'.($moreparam?$moreparam:'').'>'; $tmp=explode(',',$size);
$newsize=$tmp[0];
$out='<input type="text" name="options_'.$key.'" size="'.$showsize.'" maxlength="'.$newsize.'" value="'.$value.'"'.($moreparam?$moreparam:'').'>';
}
else if (in_array($type,array('int','double')))
{
$tmp=explode(',',$size);
$newsize=$tmp[0];
$out='<input type="text" name="options_'.$key.'" size="'.$showsize.'" maxlength="'.$newsize.'" value="'.$value.'"'.($moreparam?$moreparam:'').'>';
} }
else if ($type == 'varchar') else if ($type == 'varchar')
{ {
@ -468,7 +486,8 @@ class ExtraFields
$doleditor=new DolEditor('options_'.$key,$value,'',200,'dolibarr_notes','In',false,false,$conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_SOCIETE,5,100); $doleditor=new DolEditor('options_'.$key,$value,'',200,'dolibarr_notes','In',false,false,$conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_SOCIETE,5,100);
$out=$doleditor->Create(1); $out=$doleditor->Create(1);
} }
else if ($type == 'date') $out.=' (YYYY-MM-DD)'; // Add comments
if ($type == 'date') $out.=' (YYYY-MM-DD)';
elseif ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)'; elseif ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)';
return $out; return $out;
} }

View File

@ -19,6 +19,8 @@ DROP TABLE llx_product_ca;
DROP TABLE llx_document; DROP TABLE llx_document;
DROP TABLE llx_dolibarr_modules; DROP TABLE llx_dolibarr_modules;
ALTER TABLE llx_extrafields MODIFY COLUMN size varchar(8) DEFAULT NULL;
ALTER TABLE llx_menu MODIFY COLUMN fk_mainmenu varchar(24); ALTER TABLE llx_menu MODIFY COLUMN fk_mainmenu varchar(24);
ALTER TABLE llx_menu MODIFY COLUMN fk_leftmenu varchar(24); ALTER TABLE llx_menu MODIFY COLUMN fk_leftmenu varchar(24);

View File

@ -28,6 +28,6 @@ create table llx_extrafields
tms timestamp, tms timestamp,
label varchar(255) NOT NULL, -- label correspondant a l'attribut label varchar(255) NOT NULL, -- label correspondant a l'attribut
type varchar(8), type varchar(8),
size integer DEFAULT 0, size varchar(8) DEFAULT NULL,
pos integer DEFAULT 0 pos integer DEFAULT 0
)ENGINE=innodb; )ENGINE=innodb;

View File

@ -339,6 +339,11 @@ OldVATRates=Old VAT rate
NewVATRates=New VAT rate NewVATRates=New VAT rate
PriceBaseTypeToChange=Modify on prices with base reference value defined on PriceBaseTypeToChange=Modify on prices with base reference value defined on
MassConvert=Launch mass convert MassConvert=Launch mass convert
String=String
TextLong=Long text
Int=Integer
Float=Float
DateAndTime=Date and hour
# Modules # Modules
Module0Name=Users & groups Module0Name=Users & groups

View File

@ -341,6 +341,11 @@ OldVATRates=Ancien taux de TVA
NewVATRates=Nouveau taux de TVA NewVATRates=Nouveau taux de TVA
PriceBaseTypeToChange=Modifier sur les prix dont la référence de base est le PriceBaseTypeToChange=Modifier sur les prix dont la référence de base est le
MassConvert=Convertir en masse MassConvert=Convertir en masse
String=Chaine
TextLong=Texte long
Int=Numérique entier
Float=Décimal
DateAndTime=Date et heure
# Modules= undefined # Modules= undefined
Module0Name= Utilisateurs & groupes Module0Name= Utilisateurs & groupes

View File

@ -36,13 +36,9 @@ $extrafields = new ExtraFields($db);
$form = new Form($db); $form = new Form($db);
// List of supported format // List of supported format
$type2label=array( $tmptype2label=getStaticMember(get_class($extrafields),'type2label');
'varchar'=>$langs->trans('String'), $type2label=array('');
'text'=>$langs->trans('Text'), foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->trans($val);
'int'=>$langs->trans('Int'),
//'date'=>$langs->trans('Date'),
//'datetime'=>$langs->trans('DateAndTime')
);
$action=GETPOST("action"); $action=GETPOST("action");
$elementtype='product'; $elementtype='product';

View File

@ -34,13 +34,9 @@ $extrafields = new ExtraFields($db);
$form = new Form($db); $form = new Form($db);
// List of supported format // List of supported format
$type2label=array( $tmptype2label=getStaticMember(get_class($extrafields),'type2label');
'varchar'=>$langs->trans('String'), $type2label=array('');
'text'=>$langs->trans('Text'), foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->trans($val);
'int'=>$langs->trans('Int'),
//'date'=>$langs->trans('Date'),
//'datetime'=>$langs->trans('DateAndTime')
);
$action=GETPOST("action"); $action=GETPOST("action");
$elementtype='company'; $elementtype='company';