From bf38ea15baa9ee6e224800b20714bd2fa73a116b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 22 Jun 2011 11:41:37 +0000 Subject: [PATCH] Enhance extrafields feature. Input and output fields can be personalised according to their format/size. --- htdocs/adherents/fiche.php | 21 ++++++--- htdocs/core/class/extrafields.class.php | 61 +++++++++++++++++++++++++ htdocs/societe/soc.php | 25 ++++++---- 3 files changed, 93 insertions(+), 14 deletions(-) diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php index 49c6b2453e2..d42a7140ec4 100644 --- a/htdocs/adherents/fiche.php +++ b/htdocs/adherents/fiche.php @@ -769,9 +769,12 @@ if ($action == 'create') print "\n"; // Attribut optionnels - foreach($extrafields->attribute_label as $key=>$value) + foreach($extrafields->attribute_label as $key=>$label) { - print "".$value.''."\n"; + $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:''); + print "".$label.''; + print $extrafields->showInputField($key,$value); + print ''."\n"; } /* @@ -980,9 +983,12 @@ if ($action == 'edit') print "\n"; // Other attributes - foreach($extrafields->attribute_label as $key=>$value) + foreach($extrafields->attribute_label as $key=>$label) { - print "".$value."array_options["options_$key"]."\">\n"; + $value=(isset($_POST["options_$key"])?$_POST["options_$key"]:$adh->array_options["options_$key"]); + print "".$label.""; + print $extrafields->showInputField($key,$value); + print "\n"; } // Third party Dolibarr @@ -1285,9 +1291,12 @@ if ($rowid && $action != 'edit') print ''.$langs->trans("Status").''.$adh->getLibStatut(4).''; // Other attributes - foreach($extrafields->attribute_label as $key=>$value) + foreach($extrafields->attribute_label as $key=>$label) { - print "".$value."".$adh->array_options["options_$key"]." \n"; + $value=$adh->array_options["options_$key"]; + print "".$label.""; + print $extrafields->showOutputField($key,$value); + print "\n"; } // Third party Dolibarr diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 082c281a537..17144f693c9 100755 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -397,5 +397,66 @@ class ExtraFields } } + + /** + * Return HTML string to put an input field into a page + * @param key Key of attribute + * @param value Value to show + * @param moreparam To add more parametes on html input tag + */ + function showInputField($key,$value,$moreparam='') + { + $label=$this->attribute_label[$key]; + $type=$this->attribute_type[$key]; + $size=$this->attribute_size[$key]; + $elementtype=$this->attribute_elementtype[$key]; + if ($type == 'date') + { + $showsize=10; + } + elseif ($type == 'int') + { + $showsize=10; + } + else + { + $showsize=round($size); + if ($showsize > 48) $showsize=48; + } + //print $type.'-'.$size; + $out=''; + if ($type == 'date') $out.=' (YYYY-MM-DD)'; + return $out; + } + + /** + * Return HTML string to put an output field into a page + * @param key Key of attribute + * @param value Value to show + */ + function showOutputField($key,$value,$moreparam='') + { + $label=$this->attribute_label[$key]; + $type=$this->attribute_type[$key]; + $size=$this->attribute_size[$key]; + $elementtype=$this->attribute_elementtype[$key]; + if ($type == 'date') + { + $showsize=10; + } + elseif ($type == 'int') + { + $showsize=10; + } + else + { + $showsize=round($size); + if ($showsize > 48) $showsize=48; + } + //print $type.'-'.$size; + $out=$value; + return $out; + } + } ?> diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index 4ad50377b07..442c96aa3dd 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -982,10 +982,13 @@ else print ''; } - // Attribut optionnels - foreach($extrafields->attribute_label as $key=>$value) + // Other attributes + foreach($extrafields->attribute_label as $key=>$label) { - print "".$value.''."\n"; + $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:''); + print "".$label.''; + print $extrafields->showInputField($key,$value); + print ''."\n"; } // Ajout du logo @@ -1130,7 +1133,7 @@ else print ''; // Name - print ''; + print ''; // Prefix if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field @@ -1407,9 +1410,12 @@ else } // Other attributes - foreach($extrafields->attribute_label as $key=>$value) + foreach($extrafields->attribute_label as $key=>$label) { - print "\n"; + $value=(isset($_POST["options_$key"])?$_POST["options_$key"]:$soc->array_options["options_$key"]); + print "\n"; } // Logo @@ -1740,9 +1746,12 @@ else } // Other attributes - foreach($extrafields->attribute_label as $key=>$value) + foreach($extrafields->attribute_label as $key=>$label) { - print "\n"; + $value=$soc->array_options["options_$key"]; + print "\n"; } // Ban
'.$langs->trans('ThirdPartyName').'
'.$langs->trans('ThirdPartyName').'
".$value."array_options["options_$key"]."\">
".$label.""; + print $extrafields->showInputField($key,$value); + print "
".$value."".$soc->array_options["options_$key"]." 
".$label.""; + print $extrafields->showOutputField($key,$value); + print "