diff --git a/ChangeLog b/ChangeLog index 52840dd2cc265689833a8620306cf98d8bc47270..2e06735cb7d4bf54c129f3ebf3991a838e100e6a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -28,6 +28,7 @@ For users: - 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 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: [ task #185 ]: Can input amount when correcting stock to recalculate PMP. - 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: Add great britain provinces. - New: Update libs/tools/logo for DoliWamp. -- 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: Add conditional substitution IF/ELSEIF/ENDIF for ODT templates +- 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: Add conditional substitution IF/ELSEIF/ENDIF for ODT templates. - 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: [ task #498 ] Improvement of the block to add products/services lines. - 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: 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 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 experimental modules: - New: Add margin and commissions management module. - New: Add holiday module. diff --git a/htdocs/adherents/admin/adherent_extrafields.php b/htdocs/adherents/admin/adherent_extrafields.php index b14042a141e2f8524e34414c657117e228c880ce..4f981a0607f8f374d21d2a8413497bd31681ada5 100755 --- a/htdocs/adherents/admin/adherent_extrafields.php +++ b/htdocs/adherents/admin/adherent_extrafields.php @@ -34,13 +34,9 @@ $extrafields = new ExtraFields($db); $form = new Form($db); // List of supported format -$type2label=array( -'varchar'=>$langs->trans('String'), -'text'=>$langs->trans('Text'), -'int'=>$langs->trans('Int'), -'date'=>$langs->trans('Date'), -'datetime'=>$langs->trans('DateAndTime') -); +$tmptype2label=getStaticMember(get_class($extrafields),'type2label'); +$type2label=array(''); +foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->trans($val); $action=GETPOST("action"); $elementtype='member'; diff --git a/htdocs/core/admin_extrafields.inc.php b/htdocs/core/admin_extrafields.inc.php index 3bd46c7abf04df5380d5dc2f8dedfe64dd608e25..5384c3c44905fb93a56474e65b3013ab5916d76f 100644 --- a/htdocs/core/admin_extrafields.inc.php +++ b/htdocs/core/admin_extrafields.inc.php @@ -24,20 +24,34 @@ $maxsizestring=255; $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 if ($action == 'add') { if ($_POST["button"] != $langs->trans("Cancel")) { // 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++; $langs->load("errors"); $mesg=$langs->trans("ErrorSizeTooLongForVarcharType",$maxsizestring); $action = 'create'; } - if (GETPOST('type')=='int' && GETPOST('size') > $maxsizeint) + if (GETPOST('type')=='int' && $extrasize > $maxsizeint) { $error++; $langs->load("errors"); @@ -50,7 +64,7 @@ if ($action == 'add') // Type et taille non encore pris en compte => varchar(255) 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) { header("Location: ".$_SERVER["PHP_SELF"]); @@ -79,14 +93,21 @@ if ($action == 'update') if ($_POST["button"] != $langs->trans("Cancel")) { // 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++; $langs->load("errors"); $mesg=$langs->trans("ErrorSizeTooLongForVarcharType",$maxsizestring); $action = 'edit'; } - if (GETPOST('type')=='int' && GETPOST('size') > $maxsizeint) + if (GETPOST('type')=='int' && $extrasize > $maxsizeint) { $error++; $langs->load("errors"); @@ -98,12 +119,12 @@ if ($action == 'update') { 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 (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"]); exit; diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 5361819f7b0d7e78b34f0bda975fb3e19170bef0..af20aaf1a030dd9c5fb3d4c35f571595f894f356 100755 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -3,7 +3,7 @@ * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org> * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org> * 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> * * This program is free software; you can redistribute it and/or modify @@ -42,6 +42,14 @@ class ExtraFields var $error; var $errno; + static $type2label=array( + 'varchar'=>'String', + 'text'=>'TextLong', + 'int'=>'Int', + 'double'=>'Float', + 'date'=>'Date', + 'datetime'=>'DateAndTime' + ); /** * Constructor @@ -74,10 +82,12 @@ class ExtraFields if (empty($attrname)) return -1; if (empty($label)) return -1; + // Create field into database $result=$this->create($attrname,$type,$size,$elementtype); $err1=$this->errno; 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); $err2=$this->errno; 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 $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 $size Size/length of attribute * @param string $elementtype Element type ('member', 'product', 'company', ...) @@ -433,8 +443,8 @@ class ExtraFields global $conf; $label=$this->attribute_label[$key]; - $type=$this->attribute_type[$key]; - $size=$this->attribute_size[$key]; + $type =$this->attribute_type[$key]; + $size =$this->attribute_size[$key]; $elementtype=$this->attribute_elementtype[$key]; if ($type == 'date') { @@ -444,7 +454,7 @@ class ExtraFields { $showsize=19; } - elseif ($type == 'int') + elseif (in_array($type,array('int','double'))) { $showsize=10; } @@ -454,9 +464,17 @@ class ExtraFields 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') { @@ -468,8 +486,9 @@ class ExtraFields $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); } - else if ($type == 'date') $out.=' (YYYY-MM-DD)'; - else if ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)'; + // Add comments + if ($type == 'date') $out.=' (YYYY-MM-DD)'; + elseif ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)'; return $out; } diff --git a/htdocs/install/mysql/migration/3.2.0-3.3.0.sql b/htdocs/install/mysql/migration/3.2.0-3.3.0.sql index bb0ef5cf9900213fd03597f7d470a583cfc7867a..2f9e4785c23974e78301e8b5baa14ce84898b230 100755 --- a/htdocs/install/mysql/migration/3.2.0-3.3.0.sql +++ b/htdocs/install/mysql/migration/3.2.0-3.3.0.sql @@ -19,6 +19,8 @@ DROP TABLE llx_product_ca; DROP TABLE llx_document; 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_leftmenu varchar(24); diff --git a/htdocs/install/mysql/tables/llx_extrafields.sql b/htdocs/install/mysql/tables/llx_extrafields.sql index 2350ec44e82606759c085534dc3163add5c08ae2..ad480d931fe48f5f312906469d203d5157e15529 100755 --- a/htdocs/install/mysql/tables/llx_extrafields.sql +++ b/htdocs/install/mysql/tables/llx_extrafields.sql @@ -28,6 +28,6 @@ create table llx_extrafields tms timestamp, label varchar(255) NOT NULL, -- label correspondant a l'attribut type varchar(8), - size integer DEFAULT 0, + size varchar(8) DEFAULT NULL, pos integer DEFAULT 0 )ENGINE=innodb; diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 00ecf965b1da8988434448e68ea1557a877cecc4..fd1549aebfdc23b31b13d2ab40549b961689ce80 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -339,6 +339,11 @@ OldVATRates=Old VAT rate NewVATRates=New VAT rate PriceBaseTypeToChange=Modify on prices with base reference value defined on MassConvert=Launch mass convert +String=String +TextLong=Long text +Int=Integer +Float=Float +DateAndTime=Date and hour # Modules Module0Name=Users & groups diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index 66dddcea49370e879f58b0ba4a1512d22c3a3550..f885285f23f9ab0c28cc607fc74a0cbf479ff6b2 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -341,6 +341,11 @@ OldVATRates=Ancien taux de TVA NewVATRates=Nouveau taux de TVA PriceBaseTypeToChange=Modifier sur les prix dont la référence de base est le MassConvert=Convertir en masse +String=Chaine +TextLong=Texte long +Int=Numérique entier +Float=Décimal +DateAndTime=Date et heure # Modules= undefined Module0Name= Utilisateurs & groupes diff --git a/htdocs/product/admin/product_extrafields.php b/htdocs/product/admin/product_extrafields.php index 7df63282be0270c671f9c2bea1a7b4d013835fa1..03a251c47dc323d5fb3132c294aa3c7494eac8f5 100755 --- a/htdocs/product/admin/product_extrafields.php +++ b/htdocs/product/admin/product_extrafields.php @@ -36,13 +36,9 @@ $extrafields = new ExtraFields($db); $form = new Form($db); // List of supported format -$type2label=array( -'varchar'=>$langs->trans('String'), -'text'=>$langs->trans('Text'), -'int'=>$langs->trans('Int'), -//'date'=>$langs->trans('Date'), -//'datetime'=>$langs->trans('DateAndTime') -); +$tmptype2label=getStaticMember(get_class($extrafields),'type2label'); +$type2label=array(''); +foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->trans($val); $action=GETPOST("action"); $elementtype='product'; diff --git a/htdocs/societe/admin/societe_extrafields.php b/htdocs/societe/admin/societe_extrafields.php index 5149bcee1acb9c4bea288f0c78200b4fc572c712..6c4e4966910910b50261bcf8973255f1ae187249 100755 --- a/htdocs/societe/admin/societe_extrafields.php +++ b/htdocs/societe/admin/societe_extrafields.php @@ -34,13 +34,9 @@ $extrafields = new ExtraFields($db); $form = new Form($db); // List of supported format -$type2label=array( -'varchar'=>$langs->trans('String'), -'text'=>$langs->trans('Text'), -'int'=>$langs->trans('Int'), -//'date'=>$langs->trans('Date'), -//'datetime'=>$langs->trans('DateAndTime') -); +$tmptype2label=getStaticMember(get_class($extrafields),'type2label'); +$type2label=array(''); +foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->trans($val); $action=GETPOST("action"); $elementtype='company';