diff --git a/htdocs/bom/tpl/objectline_create.tpl.php b/htdocs/bom/tpl/objectline_create.tpl.php
index d29cdb7c6bb..e486269b108 100644
--- a/htdocs/bom/tpl/objectline_create.tpl.php
+++ b/htdocs/bom/tpl/objectline_create.tpl.php
@@ -142,7 +142,7 @@ print '';
print '';
if (is_object($objectline)) {
- print $objectline->showOptionals($extrafields, 'edit', array('style'=>$bcnd[$var], 'colspan'=>$coldisplay), '', '', 1);
+ print $objectline->showOptionals($extrafields, 'edit', array('style'=>$bcnd[$var], 'colspan'=>$coldisplay), '', '', 1, 'line');
}
?>
diff --git a/htdocs/bom/tpl/objectline_edit.tpl.php b/htdocs/bom/tpl/objectline_edit.tpl.php
index 77638b875ff..5e6530a1cbc 100644
--- a/htdocs/bom/tpl/objectline_edit.tpl.php
+++ b/htdocs/bom/tpl/objectline_edit.tpl.php
@@ -142,7 +142,7 @@ print '';
print '';
if (is_object($objectline)) {
- print $objectline->showOptionals($extrafields, 'edit', array('style'=>$bcnd[$var], 'colspan'=>$coldisplay), '', '', 1);
+ print $objectline->showOptionals($extrafields, 'edit', array('style'=>$bcnd[$var], 'colspan'=>$coldisplay), '', '', 1, 'line');
}
print "\n";
diff --git a/htdocs/bom/tpl/objectline_view.tpl.php b/htdocs/bom/tpl/objectline_view.tpl.php
index 87c1a72789d..bc8506b2151 100644
--- a/htdocs/bom/tpl/objectline_view.tpl.php
+++ b/htdocs/bom/tpl/objectline_view.tpl.php
@@ -161,7 +161,7 @@ print '';
//Line extrafield
if (!empty($extrafields))
{
- print $line->showOptionals($extrafields, 'view', array('style'=>'class="drag drop oddeven"', 'colspan'=>$coldisplay), '', '', 1);
+ print $line->showOptionals($extrafields, 'view', array('style'=>'class="drag drop oddeven"', 'colspan'=>$coldisplay), '', '', 1, 'line');
}
print "\n";
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 0a9b7838e97..ed4c0e4ebc0 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -6753,9 +6753,10 @@ abstract class CommonObject
* @param string $keysuffix Suffix string to add after name and id of field (can be used to avoid duplicate names)
* @param string $keyprefix Prefix string to add before name and id of field (can be used to avoid duplicate names)
* @param string $onetrtd All fields in same tr td. Used by objectline_create.tpl.php for example.
+ * @param string $display_type "card" for form display, "line" for document line display (extrafields on propal line, order line, etc...)
* @return string
*/
- public function showOptionals($extrafields, $mode = 'view', $params = null, $keysuffix = '', $keyprefix = '', $onetrtd = 0)
+ public function showOptionals($extrafields, $mode = 'view', $params = null, $keysuffix = '', $keyprefix = '', $onetrtd = 0, $display_type = 'card')
{
global $db, $conf, $langs, $action, $form, $hookmanager;
@@ -6810,7 +6811,7 @@ abstract class CommonObject
}
$colspan = '';
- if (is_array($params) && count($params) > 0) {
+ if (is_array($params) && count($params) > 0 && $display_type=='card') {
if (array_key_exists('cols', $params)) {
$colspan = $params['cols'];
} elseif (array_key_exists('colspan', $params)) { // For backward compatibility. Use cols instead now.
@@ -6868,7 +6869,7 @@ abstract class CommonObject
}
}
- $out .= $extrafields->showSeparator($key, $this, ($colspan + 1));
+ $out .= $extrafields->showSeparator($key, $this, ($colspan + 1), $display_type);
} else {
$class = (!empty($extrafields->attributes[$this->table_element]['hidden'][$key]) ? 'hideobject ' : '');
$csstyle = '';
@@ -6887,10 +6888,11 @@ abstract class CommonObject
$domData .= ' data-targetid="'.$this->id.'"';
$html_id = (empty($this->id) ? '' : 'extrarow-'.$this->element.'_'.$key.'_'.$this->id);
+ if ($display_type=='card') {
+ if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) { $colspan = '0'; }
- if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) { $colspan = '0'; }
-
- if ($action == 'selectlines') { $colspan++; }
+ if ($action == 'selectlines') { $colspan++; }
+ }
// Convert date into timestamp format (value in memory must be a timestamp)
if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date', 'datetime')))
@@ -6917,11 +6919,13 @@ abstract class CommonObject
$labeltoshow = $langs->trans($label);
$helptoshow = $langs->trans($extrafields->attributes[$this->table_element]['help'][$key]);
- $out .= '
';
- else $out .= '';
+ if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) {
+ $out .= ($display_type=='card' ? '' : '');
+ } else {
+ $out .= ($display_type=='card' ? '' : '');
+ }
$e++;
}
}
diff --git a/htdocs/core/class/commonobjectline.class.php b/htdocs/core/class/commonobjectline.class.php
index 806e0f2a663..0d4cfbe4f34 100644
--- a/htdocs/core/class/commonobjectline.class.php
+++ b/htdocs/core/class/commonobjectline.class.php
@@ -100,255 +100,4 @@ abstract class CommonObjectLine extends CommonObject
// Currently we need function at end of file CommonObject for all object lines. Should find a way to avoid duplicate code.
// For the moment we use the extends on CommonObject until PHP min is 5.4 so use Traits.
-
- /**
- * Function to show lines of extrafields with output datas.
- * This function is responsible to output the and | according to correct number of columns received into $params['colspan']
- *
- * @param Extrafields $extrafields Extrafield Object
- * @param string $mode Show output ('view') or input ('create' or 'edit') for extrafield
- * @param array $params Optional parameters. Example: array('style'=>'class="oddeven"', 'colspan'=>$colspan)
- * @param string $keysuffix Suffix string to add after name and id of field (can be used to avoid duplicate names)
- * @param string $keyprefix Prefix string to add before name and id of field (can be used to avoid duplicate names)
- * @param string $onetrtd All fields in same tr td. Used by objectline_create.tpl.php for example.
- * @return string
- */
- public function showOptionals($extrafields, $mode = 'view', $params = null, $keysuffix = '', $keyprefix = '', $onetrtd = 0)
- {
- global $db, $conf, $langs, $action, $form, $hookmanager;
-
- if (!is_object($form)) $form = new Form($db);
-
- $out = '';
-
- $parameters = array();
- $reshook = $hookmanager->executeHooks('showOptionals', $parameters, $this, $action); // Note that $action and $object may have been modified by hook
- if (empty($reshook))
- {
- if (is_array($extrafields->attributes[$this->table_element]['label']) && count($extrafields->attributes[$this->table_element]['label']) > 0)
- {
- $out .= "\n";
- $out .= ' ';
- $out .= "\n";
-
- $extrafields_collapse_num = '';
- $e = 0;
- foreach ($extrafields->attributes[$this->table_element]['label'] as $key=>$label)
- {
- // Show only the key field in params
- if (is_array($params) && array_key_exists('onlykey', $params) && $key != $params['onlykey']) continue;
-
- // Test on 'enabled' ('enabled' is different than 'list' = 'visibility')
- $enabled = 1;
- if ($enabled && isset($extrafields->attributes[$this->table_element]['enabled'][$key]))
- {
- $enabled = dol_eval($extrafields->attributes[$this->table_element]['enabled'][$key], 1);
- }
- if (empty($enabled)) continue;
-
- $visibility = 1;
- if ($visibility && isset($extrafields->attributes[$this->table_element]['list'][$key]))
- {
- $visibility = dol_eval($extrafields->attributes[$this->table_element]['list'][$key], 1);
- }
-
- $perms = 1;
- if ($perms && isset($extrafields->attributes[$this->table_element]['perms'][$key]))
- {
- $perms = dol_eval($extrafields->attributes[$this->table_element]['perms'][$key], 1);
- }
-
- if (($mode == 'create') && abs($visibility) != 1 && abs($visibility) != 3) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list
- elseif (($mode == 'edit') && abs($visibility) != 1 && abs($visibility) != 3 && abs($visibility) != 4) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list and <> 4 = not visible at the creation
- elseif ($mode == 'view' && empty($visibility)) continue;
- if (empty($perms)) continue;
- // Load language if required
- if (!empty($extrafields->attributes[$this->table_element]['langfile'][$key])) {
- $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]);
- }
-
- switch ($mode) {
- case "view":
- $value = $this->array_options["options_".$key.$keysuffix]; // Value may be clean or formated later
- break;
- case "create":
- case "edit":
- // We get the value of property found with GETPOST so it takes into account:
- // default values overwrite, restore back to list link, ... (but not 'default value in database' of field)
- $check = 'alphanohtml';
- if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('html', 'text'))) {
- $check = 'restricthtml';
- }
- $getposttemp = GETPOST($keyprefix.'options_'.$key.$keysuffix, $check, 3); // GETPOST can get value from GET, POST or setup of default values overwrite.
- // GETPOST("options_" . $key) can be 'abc' or array(0=>'abc')
- if (is_array($getposttemp) || $getposttemp != '' || GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix))
- {
- if (is_array($getposttemp)) {
- // $getposttemp is an array but following code expects a comma separated string
- $value = implode(",", $getposttemp);
- } else {
- $value = $getposttemp;
- }
- } else {
- $value = $this->array_options["options_".$key]; // No GET, no POST, no default value, so we take value of object.
- }
- //var_dump($keyprefix.' - '.$key.' - '.$keysuffix.' - '.$keyprefix.'options_'.$key.$keysuffix.' - '.$this->array_options["options_".$key.$keysuffix].' - '.$getposttemp.' - '.$value);
- break;
- }
-
- if ($extrafields->attributes[$this->table_element]['type'][$key] == 'separate')
- {
- $extrafields_collapse_num = '';
- $extrafield_param = $extrafields->attributes[$this->table_element]['param'][$key];
- if (!empty($extrafield_param) && is_array($extrafield_param)) {
- $extrafield_param_list = array_keys($extrafield_param['options']);
-
- if (count($extrafield_param_list) > 0) {
- $extrafield_collapse_display_value = intval($extrafield_param_list[0]);
-
- if ($extrafield_collapse_display_value == 1 || $extrafield_collapse_display_value == 2) {
- $extrafields_collapse_num = $extrafields->attributes[$this->table_element]['pos'][$key];
- }
- }
- }
-
- $out .= $extrafields->showSeparator($key, $this, 0, 'line');
- } else {
- $class = (!empty($extrafields->attributes[$this->table_element]['hidden'][$key]) ? 'hideobject ' : '');
- $csstyle = '';
- if (is_array($params) && count($params) > 0) {
- if (array_key_exists('class', $params)) {
- $class .= $params['class'].' ';
- }
- if (array_key_exists('style', $params)) {
- $csstyle = $params['style'];
- }
- }
-
- // add html5 elements
- $domData = ' data-element="extrafield"';
- $domData .= ' data-targetelement="'.$this->element.'"';
- $domData .= ' data-targetid="'.$this->id.'"';
-
- $html_id = (empty($this->id) ? '' : 'extrarow-'.$this->element.'_'.$key.'_'.$this->id);
-
- // Convert date into timestamp format (value in memory must be a timestamp)
- if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date', 'datetime')))
- {
- $datenotinstring = $this->array_options['options_'.$key];
- if (!is_numeric($this->array_options['options_'.$key])) // For backward compatibility
- {
- $datenotinstring = $this->db->jdate($datenotinstring);
- }
- $value = (GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)) ? dol_mktime(GETPOST($keyprefix.'options_'.$key.$keysuffix."hour", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."min", 'int', 3), 0, GETPOST($keyprefix.'options_'.$key.$keysuffix."month", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."day", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."year", 'int', 3)) : $datenotinstring;
- }
- // Convert float submited string into real php numeric (value in memory must be a php numeric)
- if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('price', 'double')))
- {
- $value = (GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix) || $value) ? price2num($value) : $this->array_options['options_'.$key];
- }
-
- // HTML, text, select, integer and varchar: take into account default value in database if in create mode
- if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('html', 'text', 'varchar', 'select', 'int')))
- {
- if ($action == 'create') $value = (GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix) || $value) ? $value : $extrafields->attributes[$this->table_element]['default'][$key];
- }
-
- $labeltoshow = $langs->trans($label);
- $helptoshow = $langs->trans($extrafields->attributes[$this->table_element]['help'][$key]);
-
- $out .= '';
- else $out .= '';
- $e++;
- }
- }
- $out .= "\n";
- // Add code to manage list depending on others
- if (!empty($conf->use_javascript_ajax)) {
- $out .= '
- '."\n";
- }
-
- $out .= ' '."\n";
- }
- }
-
- $out .= $hookmanager->resPrint;
-
- return $out;
- }
}
diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php
index 0e0f5acd4a4..0800a568d84 100644
--- a/htdocs/core/class/extrafields.class.php
+++ b/htdocs/core/class/extrafields.class.php
@@ -1902,19 +1902,20 @@ class ExtraFields
* @param string $key Key of attribute
* @param string $object Object
* @param int $colspan Value of colspan to use (it must includes the first column with title)
- * @param string $typeform "card" for from display, "line" for docuement line display (exstraiedls on propal line, order line, etc...)
+ * @param string $display_type "card" for form display, "line" for document line display (extrafields on propal line, order line, etc...)
* @return string HTML code with line for separator
*/
- public function showSeparator($key, $object, $colspan = 2, $typeform='card')
+ public function showSeparator($key, $object, $colspan = 2, $display_type = 'card')
{
global $langs;
- if ($typeform=='card') {
+ if ($display_type=='card') {
$tagtype='tr';
$tagtype_dyn='td';
- }elseif ($typeform=='line') {
+ }elseif ($display_type=='line') {
$tagtype='div';
$tagtype_dyn='span';
+ $colspan=0;
}
$out = '<'.$tagtype.' id="trextrafieldseparator'.$key.(!empty($object->id)?'_'.$object->id:'').'" class="trextrafieldseparator trextrafieldseparator'.$key.(!empty($object->id)?'_'.$object->id:'').'">';
diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php
index cced0915681..dcc2257f2c5 100644
--- a/htdocs/core/tpl/objectline_create.tpl.php
+++ b/htdocs/core/tpl/objectline_create.tpl.php
@@ -321,7 +321,7 @@ if ($nolinesbefore) {
}
if (is_object($objectline)) {
print '';
}
echo ' | ';
diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php
index 3115e4e2f0c..a174c82544d 100644
--- a/htdocs/core/tpl/objectline_edit.tpl.php
+++ b/htdocs/core/tpl/objectline_edit.tpl.php
@@ -129,7 +129,7 @@ $coldisplay++;
if (!empty($extrafields))
{
print '';
}
diff --git a/htdocs/core/tpl/objectline_view.tpl.php b/htdocs/core/tpl/objectline_view.tpl.php
index 337970412de..e4ca44438f7 100644
--- a/htdocs/core/tpl/objectline_view.tpl.php
+++ b/htdocs/core/tpl/objectline_view.tpl.php
@@ -162,7 +162,7 @@ if (($line->info_bits & 2) == 2) {
if (!empty($extrafields))
{
print '';
}
}