From ec52f54a522a0a6291f137d657c925c041271f17 Mon Sep 17 00:00:00 2001 From: jfefe Date: Mon, 1 Apr 2013 18:59:05 +0200 Subject: [PATCH] Unique function to show input or output of extrafields datas --- htdocs/core/class/commonobject.class.php | 104 +++++++++++++---------- 1 file changed, 60 insertions(+), 44 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index f9a1bad9ef7..43fb4234558 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2190,59 +2190,75 @@ abstract class CommonObject else return 0; } - /** + /** * Function to show lines of extrafields with output datas * * @param object $extrafields extrafield Object + * @param string $mode Show output (view) or input (edit) for extrafield * * return string */ - function showOptionals($extrafields) + function showOptionals($extrafields,$mode='view') { - global $_POST; + global $_POST; - $out = ''; + $out = ''; - if (! empty($this->array_options)) - { - $e = 0; - foreach($extrafields->attribute_label as $key=>$label) - { - $colspan='3'; - $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$this->array_options["options_".$key]); - if ($extrafields->attribute_type[$key] == 'separate') - { - $out = $extrafields->showSeparator($key); - } - else - { - if ( !empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) - { - $out .= ''; - $colspan='0'; - } - else - { - $out .= ''; - } - // Convert date into timestamp format - if (in_array($extrafields->attribute_type[$key],array('date','datetime'))) - { - $value = isset($_POST["options_".$key])?dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]):$this->array_options['options_'.$key]; - } - $out .= ''.$label.''; - $out .=''; - $out .= $extrafields->showOutputField($key,$value); - $out .= ''."\n"; - - if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) $out .= ''; - else $out .= ''; - $e++; - } - } - } - return $out; - } + if(count($extrafields->attribute_label) > 0) + { + $out .= "\n"; + $out .= ' '; + $out .= "\n"; + + $e = 0; + foreach($extrafields->attribute_label as $key=>$label) + { + $colspan='3'; + $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$this->array_options["options_".$key]); + if ($extrafields->attribute_type[$key] == 'separate') + { + $out .= $extrafields->showSeparator($key); + } + else + { + if ( !empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) + { + $out .= ''; + $colspan='0'; + } + else + { + $out .= ''; + } + // Convert date into timestamp format + if (in_array($extrafields->attribute_type[$key],array('date','datetime'))) + { + $value = isset($_POST["options_".$key])?dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]):$this->array_options['options_'.$key]; + } + $out .= ''.$label.''; + $out .=''; + + switch($mode) { + case "view": + $out .= $extrafields->showOutputField($key,$value); + break; + case "edit": + $out .= $extrafields->showInputField($key,$value); + break; + } + + $out .= ''."\n"; + + if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) $out .= ''; + else $out .= ''; + $e++; + } + } + $out .= "\n"; + $out .= ' '; + } + return $out; + } /**