';
+
+ $extrafield_param = $this->attributes[$object->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) {
+ // Set the collapse_display status to cookie in priority or if ignorecollapsesetup is 1, if cookie and ignorecollapsesetup not defined, use the setup.
+ $collapse_display = ((isset($_COOKIE['DOLCOLLAPSE_'.$object->table_element.'_extrafields_'.$key]) || GETPOST('ignorecollapsesetup', 'int')) ? ($_COOKIE['DOLCOLLAPSE_'.$object->table_element.'_extrafields_'.$key] ? true : false) : ($extrafield_collapse_display_value == 2 ? false : true));
+ $extrafields_collapse_num = $this->attributes[$object->table_element]['pos'][$key];
+
+ $out .= '';
+ $out .= '';
+ }
+ }
+ }
+
+ return $out;
+ }
+
+ /**
+ * Fill array_options property of object by extrafields value (using for data sent by forms)
+ *
+ * @param array $extralabels Deprecated (old $array of extrafields, now set this to null)
+ * @param object $object Object
+ * @param string $onlykey Only the following key is filled. When we make update of only one extrafield ($action = 'update_extras'), calling page must set this to avoid to have other extrafields being reset.
+ * @return int 1 if array_options set, 0 if no value, -1 if error (field required missing for example)
+ */
+ public function setOptionalsFromPost($extralabels, &$object, $onlykey = '')
+ {
+ global $_POST, $langs;
+
+ $nofillrequired = 0; // For error when required field left blank
+ $error_field_required = array();
+
+ if (is_array($this->attributes[$object->table_element]['label'])) $extralabels = $this->attributes[$object->table_element]['label'];
+
+ if (is_array($extralabels))
+ {
+ // Get extra fields
+ foreach ($extralabels as $key => $value)
+ {
+ if (!empty($onlykey) && $key != $onlykey) continue;
+
+ $key_type = $this->attributes[$object->table_element]['type'][$key];
+ if ($key_type == 'separate') continue;
+
+ $enabled = 1;
+ if (isset($this->attributes[$object->table_element]['list'][$key]))
+ {
+ $enabled = dol_eval($this->attributes[$object->table_element]['list'][$key], 1);
+ }
+ $perms = 1;
+ if (isset($this->attributes[$object->table_element]['perms'][$key]))
+ {
+ $perms = dol_eval($this->attributes[$object->table_element]['perms'][$key], 1);
+ }
+ if (empty($enabled)) continue;
+ if (empty($perms)) continue;
+
+ if ($this->attributes[$object->table_element]['required'][$key]) // Value is required
+ {
+ // Check if empty without using GETPOST, value can be alpha, int, array, etc...
+ if ((!is_array($_POST["options_".$key]) && empty($_POST["options_".$key]) && $this->attributes[$object->table_element]['type'][$key] != 'select' && $_POST["options_".$key] != '0')
+ || (!is_array($_POST["options_".$key]) && empty($_POST["options_".$key]) && $this->attributes[$object->table_element]['type'][$key] == 'select')
+ || (is_array($_POST["options_".$key]) && empty($_POST["options_".$key])))
+ {
+ //print 'ccc'.$value.'-'.$this->attributes[$object->table_element]['required'][$key];
+ $nofillrequired++;
+ $error_field_required[] = $langs->transnoentitiesnoconv($value);
+ }
+ }
+
+ if (in_array($key_type, array('date')))
+ {
+ // Clean parameters
+ // TODO GMT date in memory must be GMT so we should add gm=true in parameters
+ $value_key = dol_mktime(0, 0, 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]);
+ }
+ elseif (in_array($key_type, array('datetime')))
+ {
+ // Clean parameters
+ // TODO GMT date in memory must be GMT so we should add gm=true in parameters
+ $value_key = dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]);
+ }
+ elseif (in_array($key_type, array('checkbox', 'chkbxlst')))
+ {
+ $value_arr = GETPOST("options_".$key, 'array'); // check if an array
+ if (!empty($value_arr)) {
+ $value_key = implode($value_arr, ',');
+ } else {
+ $value_key = '';
+ }
+ }
+ elseif (in_array($key_type, array('price', 'double')))
+ {
+ $value_arr = GETPOST("options_".$key, 'alpha');
+ $value_key = price2num($value_arr);
+ }
+ else
+ {
+ $value_key = GETPOST("options_".$key);
+ if (in_array($key_type, array('link')) && $value_key == '-1') $value_key = '';
+ }
+
+ $object->array_options["options_".$key] = $value_key;
+ }
+
+ if ($nofillrequired) {
+ $langs->load('errors');
+ setEventMessages($langs->trans('ErrorFieldsRequired').' : '.implode(', ', $error_field_required), null, 'errors');
+ return -1;
+ }
+ else {
+ return 1;
+ }
+ }
+ else {
+ return 0;
+ }
+ }
+
+ /**
+ * return array_options array of data of extrafields value of object sent by a search form
+ *
+ * @param array|string $extrafieldsobjectkey array of extrafields (old usage) or value of object->table_element (new usage)
+ * @param string $keyprefix Prefix string to add into name and id of field (can be used to avoid duplicate names)
+ * @param string $keysuffix Suffix string to add into name and id of field (can be used to avoid duplicate names)
+ * @return array|int array_options set or 0 if no value
+ */
+ public function getOptionalsFromPost($extrafieldsobjectkey, $keyprefix = '', $keysuffix = '')
+ {
+ global $_POST;
+
+ if (is_string($extrafieldsobjectkey) && is_array($this->attributes[$extrafieldsobjectkey]['label']))
+ {
+ $extralabels = $this->attributes[$extrafieldsobjectkey]['label'];
+ }
+ else
+ {
+ $extralabels = $extrafieldsobjectkey;
+ }
+
+ if (is_array($extralabels))
+ {
+ $array_options = array();
+
+ // Get extra fields
+ foreach ($extralabels as $key => $value)
+ {
+ $key_type = '';
+ if (is_string($extrafieldsobjectkey))
+ {
+ $key_type = $this->attributes[$extrafieldsobjectkey]['type'][$key];
+ }
+
+ if (in_array($key_type, array('date', 'datetime')))
+ {
+ if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix."year")) continue; // Value was not provided, we should not set it.
+ // Clean parameters
+ $value_key = dol_mktime(GETPOST($keysuffix."options_".$key.$keyprefix."hour", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."min", 'int'), 0, GETPOST($keysuffix."options_".$key.$keyprefix."month", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."day", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."year", 'int'));
+ }
+ elseif (in_array($key_type, array('checkbox', 'chkbxlst')))
+ {
+ if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix)) continue; // Value was not provided, we should not set it.
+ $value_arr = GETPOST($keysuffix."options_".$key.$keyprefix);
+ // Make sure we get an array even if there's only one checkbox
+ $value_arr = (array) $value_arr;
+ $value_key = implode(',', $value_arr);
+ }
+ elseif (in_array($key_type, array('price', 'double', 'int')))
+ {
+ if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix)) continue; // Value was not provided, we should not set it.
+ $value_arr = GETPOST($keysuffix."options_".$key.$keyprefix);
+ $value_key = price2num($value_arr);
+ }
+ else
+ {
+ if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix)) continue; // Value was not provided, we should not set it.
+ $value_key = GETPOST($keysuffix."options_".$key.$keyprefix);
+ }
+
+ $array_options[$keysuffix."options_".$key] = $value_key; // No keyprefix here. keyprefix is used only for read.
+ }
+
+ return $array_options;
+ }
+
+ return 0;
+ }
+}
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 9f8e02e4948..0b8185b3854 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -329,12 +329,24 @@ class Form
*/
public function widgetForTranslation($fieldname, $object, $perm, $typeofdata = 'string', $check = '', $morecss = '')
{
- global $conf, $langs;
+ global $conf, $langs, $extralanguages;
$result = '';
- if (! empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE)) {
- $langcode = $conf->global->PDF_USE_ALSO_LANGUAGE_CODE;
+ // List of extra languages
+ $arrayoflangcode = array();
+ if (! empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE)) $arrayoflangcode[] = $conf->global->PDF_USE_ALSO_LANGUAGE_CODE;
+
+ if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
+ if (! is_object($extralanguages)) {
+ include_once DOL_DOCUMENT_ROOT.'/core/class/extralanguages.class.php';
+ $extralanguages = new ExtraLanguages($this->db);
+ }
+ $extralanguages->fetch_name_extralanguages('societe');
+
+ if (! is_array($extralanguages->attributes[$object->element]) || empty($extralanguages->attributes[$object->element][$fieldname])) {
+ return ''; // No extralang field to show
+ }
$result .='
';
$s=img_picto($langs->trans("ShowOtherLanguages"), 'language', '', false, 0, 0, '', 'fa-15 editfieldlang');
@@ -343,22 +355,28 @@ class Form
$result .='