diff --git a/htdocs/core/admin_extrafields.inc.php b/htdocs/core/admin_extrafields.inc.php index 46ed7d0c051..29c71f9ba45 100644 --- a/htdocs/core/admin_extrafields.inc.php +++ b/htdocs/core/admin_extrafields.inc.php @@ -28,6 +28,7 @@ $extrasize=GETPOST('size'); if (GETPOST('type')=='double' && strpos($extrasize,',')===false) $extrasize='24,8'; if (GETPOST('type')=='date') $extrasize=''; if (GETPOST('type')=='datetime') $extrasize=''; +if (GETPOST('type')=='select') $extrasize=''; // Add attribute @@ -58,13 +59,29 @@ if ($action == 'add') $mesg=$langs->trans("ErrorSizeTooLongForIntType",$maxsizeint); $action = 'create'; } + if (GETPOST('type')=='select' && !GETPOST('extra_value')) + { + $error++; + $langs->load("errors"); + $mesg=$langs->trans("ErrorNoValueForSelectType"); + $action = 'create'; + } if (! $error) { // 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'],$extrasize,$elementtype,(GETPOST('unique')?1:0),(GETPOST('required')?1:0)); + // Construct array for parameter (value of select list) + $parameters = GETPOST('extra_value'); + $parameters_array = explode("\r\n",$parameters); + foreach($parameters_array as $param_ligne) + { + list($key,$value) = explode(',',$param_ligne); + $params['options'][$key] = $value; + } + + $result=$extrafields->addExtraField($_POST['attrname'],$_POST['label'],$_POST['type'],$_POST['pos'],$extrasize,$elementtype,(GETPOST('unique')?1:0),(GETPOST('required')?1:0),$default_value,$params); if ($result > 0) { header("Location: ".$_SERVER["PHP_SELF"]); diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 799200ca5bf..0fd57fed96d 100755 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -38,6 +38,8 @@ class ExtraFields var $attribute_label; // Tableau contenant le nom des champs en clef et la taille de ces champs en value var $attribute_size; + // Tableau contenant le nom des choix en clef et la valeur de ces choix en value + var $attribute_choice; // Array to store if attribute is unique or not var $attribute_unique; // Array to store if attribute is required or not @@ -56,7 +58,8 @@ class ExtraFields 'boolean'=>'Boolean', 'price'=>'ExtrafieldPrice', 'phone'=>'ExtrafieldPhone', - 'mail'=>'ExtrafieldMail' + 'mail'=>'ExtrafieldMail', + 'select' => 'ExtrafieldSelect' ); /** @@ -87,20 +90,22 @@ class ExtraFields * @param string $elementtype Element type ('member', 'product', 'company', ...) * @param int $unique Is field unique or not * @param int $required Is field required or not + * @param array $param Params for field * @return int <=0 if KO, >0 if OK */ - function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique=0, $required=0) + function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique=0, $required=0,$default_value='', $param=0) { if (empty($attrname)) return -1; if (empty($label)) return -1; + // Create field into database - $result=$this->create($attrname,$type,$size,$elementtype, $unique, $required); + $result=$this->create($attrname,$type,$size,$elementtype, $unique, $required, $default_value,$param); $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, $unique, $required); + $result2=$this->create_label($attrname,$label,$type,$pos,$size,$elementtype, $unique, $required, $param); $err2=$this->errno; if ($result2 > 0 || ($err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' && $err2 == 'DB_ERROR_RECORD_ALREADY_EXISTS')) { @@ -126,12 +131,15 @@ class ExtraFields * @param string $elementtype Element type ('member', 'product', 'company', 'contact', ...) * @param int $unique Is field unique or not * @param int $required Is field required or not + * @param string $default_value Default value for field + * @param array $param Params for field (ex for select list : array('options'=>array('value'=>'label of option')) + * * @return int <=0 if KO, >0 if OK */ - private function create($attrname, $type='varchar', $length=255, $elementtype='member', $unique=0, $required=0) + private function create($attrname, $type='varchar', $length=255, $elementtype='member', $unique=0, $required=0, $default_value='',$param='') { $table=$elementtype.'_extrafields'; - + // Special case for not normalized table names if ($elementtype == 'member') $table='adherent_extrafields'; elseif ($elementtype == 'company') $table='societe_extrafields'; @@ -151,11 +159,20 @@ class ExtraFields }elseif($type=='mail') { $typedb='varchar'; $lengthdb='128'; + } elseif ($type=='select') { + $typedb='text'; + $lengthdb=''; } else { $typedb=$type; $lengthdb=$length; } - $field_desc = array('type'=>$typedb, 'value'=>$lengthdb, 'null'=>($required?'NOT NULL':'NULL')); + $field_desc = array( + 'type'=>$typedb, + 'value'=>$lengthdb, + 'null'=>($required?'NOT NULL':'NULL'), + 'default' => $default_value + ); + $result=$this->db->DDLAddField(MAIN_DB_PREFIX.$table, $attrname, $field_desc); if ($result > 0) { @@ -190,19 +207,33 @@ class ExtraFields * @param string $elementtype Element type ('member', 'product', 'company', ...) * @param int $unique Is field unique or not * @param int $required Is field required or not + * @param array $param Params for field (ex for select list : array('value'=>'label of option') ) * @return int <=0 if KO, >0 if OK */ - private function create_label($attrname, $label='', $type='', $pos=0, $size=0, $elementtype='member', $unique=0, $required=0) + private function create_label($attrname, $label='', $type='', $pos=0, $size=0, $elementtype='member', $unique=0, $required=0,$param) { global $conf; // Clean parameters if (empty($pos)) $pos=0; - + if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields(name, label, type, pos, size, entity, elementtype, fieldunique, fieldrequired)"; + if(is_array($param) and count($param) > 0) + { + $params = $this->db->escape(serialize($param)); + } + elseif (strlen($param) > 0) + { + $params = trim($param); + } + else + { + $params=''; + } + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields(name, label, type, pos, size, entity, elementtype, fieldunique, fieldrequired, param)"; $sql.= " VALUES('".$attrname."',"; $sql.= " '".$this->db->escape($label)."',"; $sql.= " '".$type."',"; @@ -211,7 +242,8 @@ class ExtraFields $sql.= " ".$conf->entity.","; $sql.= " '".$elementtype."',"; $sql.= " '".$unique."',"; - $sql.= " '".$required."'"; + $sql.= " '".$required."',"; + $sql.= " '".$params."'"; $sql.=')'; dol_syslog(get_class($this)."::create_label sql=".$sql); @@ -480,7 +512,7 @@ class ExtraFields if (!$forceload && !empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return $array_name_label; - $sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired"; + $sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param"; $sql.= " FROM ".MAIN_DB_PREFIX."extrafields"; $sql.= " WHERE entity = ".$conf->entity; if ($elementtype) $sql.= " AND elementtype = '".$elementtype."'"; @@ -502,6 +534,7 @@ class ExtraFields $this->attribute_elementtype[$tab->name]=$tab->elementtype; $this->attribute_unique[$tab->name]=$tab->fieldunique; $this->attribute_required[$tab->name]=$tab->fieldrequired; + $this->attribute_param[$tab->name]=unserialize($tab->param); } } return $array_name_label; @@ -531,6 +564,7 @@ class ExtraFields $elementtype=$this->attribute_elementtype[$key]; $unique=$this->attribute_unique[$key]; $required=$this->attribute_required[$key]; + $param=$this->attribute_param[$key]; if ($type == 'date') { $showsize=10; @@ -593,6 +627,15 @@ class ExtraFields { $out=' '.$langs->getCurrencySymbol($conf->currency); } + elseif ($type == 'select') + { + $out=''; + } // Add comments if ($type == 'date') $out.=' (YYYY-MM-DD)'; elseif ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)'; @@ -617,6 +660,7 @@ class ExtraFields $elementtype=$this->attribute_elementtype[$key]; $unique=$this->attribute_unique[$key]; $required=$this->attribute_required[$key]; + $params=$this->attribute_param[$key]; if ($type == 'date') { $showsize=10; @@ -649,6 +693,10 @@ class ExtraFields { $value=price($value).' '.$langs->getCurrencySymbol($conf->currency); } + elseif ($type == 'select') + { + $value=$params['options'][$value]; + } else { $showsize=round($size); diff --git a/htdocs/core/tpl/admin_extrafields_add.tpl.php b/htdocs/core/tpl/admin_extrafields_add.tpl.php index 01190bf4405..0af2b782912 100644 --- a/htdocs/core/tpl/admin_extrafields_add.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_add.tpl.php @@ -25,14 +25,22 @@ var size = jQuery("#size"); var unique = jQuery("#unique"); var required = jQuery("#required"); - if (type == 'date') { size.val('').attr('disabled','disabled'); unique.removeAttr('disabled','disabled'); } - else if (type == 'datetime') { size.val('').attr('disabled','disabled'); unique.removeAttr('disabled','disabled'); } - else if (type == 'double') { size.val('24,8').removeAttr('disabled'); unique.removeAttr('disabled','disabled'); } - else if (type == 'int') { size.val('10').removeAttr('disabled'); unique.removeAttr('disabled','disabled'); } - else if (type == 'text') { size.val('2000').removeAttr('disabled'); unique.attr('disabled','disabled').removeAttr('checked'); } - else if (type == 'varchar') { size.val('255').removeAttr('disabled'); unique.removeAttr('disabled','disabled'); } - else if (type == 'boolean') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled');} - else if (type == 'price') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled');} + + + if (type == 'date') { size.val('').attr('disabled','disabled'); unique.removeAttr('disabled','disabled'); jQuery("#value_choice").hide(); } + else if (type == 'datetime') { size.val('').attr('disabled','disabled'); unique.removeAttr('disabled','disabled'); jQuery("#value_choice").hide(); } + else if (type == 'double') { size.val('24,8').removeAttr('disabled'); unique.removeAttr('disabled','disabled'); jQuery("#value_choice").hide(); } + else if (type == 'int') { size.val('10').removeAttr('disabled'); unique.removeAttr('disabled','disabled'); jQuery("#value_choice").hide(); } + else if (type == 'text') { size.val('2000').removeAttr('disabled'); unique.attr('disabled','disabled').removeAttr('checked'); jQuery("#value_choice").hide(); } + else if (type == 'varchar') { size.val('255').removeAttr('disabled'); unique.removeAttr('disabled','disabled'); jQuery("#value_choice").hide(); } + else if (type == 'boolean') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").hide();} + else if (type == 'price') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").hide();} + else if (type == 'select') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").show();} else size.val('').attr('disabled','disabled'); } init_typeoffields(''); @@ -56,6 +64,17 @@ trans("Type"); ?> selectarray('type',$type2label,GETPOST('type')); ?> + + + + trans("Value"); ?> + + + + + + +trans("DefaultValue"); ?>"> trans("Size"); ?> diff --git a/htdocs/install/mysql/migration/3.3.0-3.4.0.sql b/htdocs/install/mysql/migration/3.3.0-3.4.0.sql index 093265e217c..1c17efb697c 100755 --- a/htdocs/install/mysql/migration/3.3.0-3.4.0.sql +++ b/htdocs/install/mysql/migration/3.3.0-3.4.0.sql @@ -35,4 +35,7 @@ ALTER TABLE llx_user add COLUMN fk_user integer; -- margin on contracts alter table llx_contratdet add column fk_product_fournisseur_price integer after info_bits; -alter table llx_contratdet add column buy_price_ht double(24,8) DEFAULT 0 after fk_product_fournisseur_price; \ No newline at end of file +alter table llx_contratdet add column buy_price_ht double(24,8) DEFAULT 0 after fk_product_fournisseur_price; + +-- serialised array, to store value of select list choices for example +alter table llx_extrafields add column param text DEFAULT '' after pos; diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 42924eb253f..090064ab0ec 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -356,6 +356,7 @@ Boolean=Boolean (Checkbox) ExtrafieldPhone = Phone ExtrafieldPrice = Price ExtrafieldMail = Email +ExtrafieldSelect = Select list LibraryToBuildPDF=Library used to build PDF WarningUsingFPDF=Warning: Your conf.php contains directive dolibarr_pdf_force_fpdf=1. This means you use the FPDF library to generate PDF files. This library is old and does not support a lot of features (Unicode, image transparency, cyrillic, arab and asiatic languages, ...), so you may experience errors during PDF generation.
To solve this and have a full support of PDF generation, please download TCPDF library, then comment or remove the line $dolibarr_pdf_force_fpdf=1, and add instead $dolibarr_lib_TCPDF_PATH='path_to_TCPDF_dir' LocalTaxDesc=Some countries apply 2 or 3 taxes on each invoice line. If this is the case, choose type for second and third tax and its rate. Possible type are:
1 : local tax apply on products and services without vat (vat is not applied on local tax)
2 : local tax apply on products and services before vat (vat is calculated on amount + localtax)
3 : local tax apply on products without vat (vat is not applied on local tax)
4 : local tax apply on products before vat (vat is calculated on amount + localtax)
5 : local tax apply on services without vat (vat is not applied on local tax)
6 : local tax apply on services before vat (vat is calculated on amount + localtax) diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 2c5f634fff6..a4c5251bb69 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -58,6 +58,7 @@ ErrorUploadBlockedByAddon=Upload blocked by a PHP/Apache plugin. ErrorFileSizeTooLarge=File size is too large. ErrorSizeTooLongForIntType=Size too long for int type (%s digits maximum) ErrorSizeTooLongForVarcharType=Size too long for string type (%s chars maximum) +ErrorNoValueForSelectType=Please fill value for select list ErrorFieldCanNotContainSpecialCharacters=Field %s must not contains special characters. ErrorNoAccountancyModuleLoaded=No accountancy module activated ErrorExportDuplicateProfil=This profil name already exists for this export set. diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index 802bbb28191..ee773c9ba46 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -351,6 +351,7 @@ Boolean=Booleen (Checkbox) ExtrafieldPhone = Téléphone ExtrafieldPrice = Prix ExtrafieldMail = Email +ExtrafieldSelect = Liste de sélection LibraryToBuildPDF=Bibliothèque utilisée pour la génération des PDF WarningUsingFPDF=Attention: Votre fichier conf.php contient la directive dolibarr_pdf_force_fpdf=1. Cela signifie que vous utilisez la librairie FPDF pour générer vos fichiers PDF. Cette librairie est ancienne et ne couvre pas de nombreuses fonctionnalitée (Unicode, transparence des images, langues cyrillic, arabes ou asiatiques...), aussi vous pouvez rencontrez des problèmes durant la génération des PDF.
Pour résoudre cela et avoir un support complet de PDF, vous pouvez télécharger la librairie TCPDF puis commenter ou supprimer la ligne $dolibarr_pdf_force_fpdf=1, et ajouter à la place $dolibarr_lib_TCPDF_PATH='chemin_vers_TCPDF' LocalTaxDesc=Certains pays appliquent 2 voir 3 taux sur chaque ligne de facture. Si c'est le cas, choisissez le type du deuxième et troisième taux et sa valeur. Les types possibles sont:
1 : taxe locale sur les produits et services hors tva (la tva n'est pas appliquée sur la taxe locale)
2 : taxe locale sur les produits et services avant tva (la tva est appliquée sur le montant + la taxe locale)
3 : taxe locale uniquement sur les produits hors tva (la tva n'est pas appliquée sur la taxe locale)
4 : taxe locale uniquement sur les produits avant tva (la tva est appliquée sur le montant + la taxe locale)
5 : taxe locale uniquement sur les services hors tva (la tva n'est pas appliquée sur la taxe locale)
6 : taxe locale uniquement sur les service avant tva (la tva est appliquée sur le montant + la taxe locale) diff --git a/htdocs/langs/fr_FR/errors.lang b/htdocs/langs/fr_FR/errors.lang index 99112a0db96..3c7d1e275ed 100644 --- a/htdocs/langs/fr_FR/errors.lang +++ b/htdocs/langs/fr_FR/errors.lang @@ -59,6 +59,7 @@ ErrorUploadBlockedByAddon=Upload bloqué par un plugin PHP/Apache. ErrorFileSizeTooLarge=La taille du fichier est trop grande. ErrorSizeTooLongForIntType=Longueur de champ trop longue pour le type int (%s chiffres maximum) ErrorSizeTooLongForVarcharType=Longueur de champ trop longue pour le type chaine (%s caractères maximum) +ErrorNoValueForSelectType=Les valeurs de la liste doivent être renseignées ErrorFieldCanNotContainSpecialCharacters=Le champ %s ne peut contenir de caractères spéciaux. ErrorNoAccountancyModuleLoaded=Aucun module de comptabilité activé ErrorExportDuplicateProfil=Ce nom de profil existe déjà pour ce lot d'export.