Work on generic multilanguage properties
This commit is contained in:
parent
239732a234
commit
4ed4644c08
@ -5064,6 +5064,9 @@ abstract class CommonObject
|
||||
if (! ($this->id > 0)) {
|
||||
return 0;
|
||||
}
|
||||
if (is_array($this->array_languages)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
$this->array_languages = array();
|
||||
|
||||
@ -5083,19 +5086,25 @@ abstract class CommonObject
|
||||
$numrows = $this->db->num_rows($resql);
|
||||
if ($numrows)
|
||||
{
|
||||
$tab = $this->db->fetch_array($resql);
|
||||
$i = 0;
|
||||
while ($i < $numrows) {
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
$key = $obj->property;
|
||||
$value = $obj->value;
|
||||
$codelang = $obj->lang;
|
||||
$type = $this->fields[$key]['type'];
|
||||
|
||||
foreach ($tab as $key => $value)
|
||||
{
|
||||
// we can add this attribute to object
|
||||
if (preg_match('/date/', $key))
|
||||
if (preg_match('/date/', $type))
|
||||
{
|
||||
$this->array_languages[$key] = $this->db->jdate($value);
|
||||
$this->array_languages[$key][$codelang] = $this->db->jdate($value);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->array_languages[$key] = $value;
|
||||
$this->array_languages[$key][$codelang] = $value;
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -5111,6 +5120,88 @@ abstract class CommonObject
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill array_options property of object by extrafields value (using for data sent by forms)
|
||||
*
|
||||
* @param string $onlykey Only the following key is filled. When we make update of only one language field ($action = 'update_languages'), calling page must set this to avoid to have other languages being reset.
|
||||
* @return int 1 if array_options set, 0 if no value, -1 if error (field required missing for example)
|
||||
*/
|
||||
public function setValuesForAlternateLanguages($onlykey = '')
|
||||
{
|
||||
global $_POST, $langs;
|
||||
|
||||
// Get extra fields
|
||||
foreach($_POST as $postfieldkey => $postfieldvalue) {
|
||||
$tmparray = explode('-', $postfieldkey);
|
||||
if ($tmparray[0] != 'field') continue;
|
||||
|
||||
$element = $tmparray[1];
|
||||
$key = $tmparray[2];
|
||||
$codelang = $tmparray[3];
|
||||
//var_dump("postfieldkey=".$postfieldkey." element=".$element." key=".$key." codelang=".$codelang);
|
||||
|
||||
if (!empty($onlykey) && $key != $onlykey) continue;
|
||||
if ($element != $this->element) continue;
|
||||
|
||||
$key_type = $this->fields[$key]['type'];
|
||||
|
||||
$enabled = 1;
|
||||
if (isset($this->fields[$key]['enabled']))
|
||||
{
|
||||
$enabled = dol_eval($this->fields[$key]['enabled'], 1);
|
||||
}
|
||||
/*$perms = 1;
|
||||
if (isset($this->fields[$key]['perms']))
|
||||
{
|
||||
$perms = dol_eval($this->fields[$key]['perms'], 1);
|
||||
}*/
|
||||
if (empty($enabled)) continue;
|
||||
//if (empty($perms)) continue;
|
||||
|
||||
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[$postfieldkey."month"], $_POST[$postfieldkey."day"], $_POST[$postfieldkey."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[$postfieldkey."hour"], $_POST[$postfieldkey."min"], 0, $_POST[$postfieldkey."month"], $_POST[$postfieldkey."day"], $_POST[$postfieldkey."year"]);
|
||||
}
|
||||
elseif (in_array($key_type, array('checkbox', 'chkbxlst')))
|
||||
{
|
||||
$value_arr = GETPOST($postfieldkey, '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($postfieldkey, 'alpha');
|
||||
$value_key = price2num($value_arr);
|
||||
}
|
||||
else
|
||||
{
|
||||
$value_key = GETPOST($postfieldkey);
|
||||
if (in_array($key_type, array('link')) && $value_key == '-1') $value_key = '';
|
||||
}
|
||||
|
||||
$this->array_languages[$key][$codelang] = $value_key;
|
||||
|
||||
/*if ($nofillrequired) {
|
||||
$langs->load('errors');
|
||||
setEventMessages($langs->trans('ErrorFieldsRequired').' : '.implode(', ', $error_field_required), null, 'errors');
|
||||
return -1;
|
||||
}*/
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Functions for extrafields */
|
||||
|
||||
|
||||
@ -343,7 +343,7 @@ class Form
|
||||
|
||||
$result .='<div class="inline-block hidden field-'.$object->element.'-'.$fieldname.'">';
|
||||
|
||||
$valuetoshow = GETPOSTISSET($fieldname."-".$langcode) ? GETPOST($fieldname."-".$langcode, $check) : '';
|
||||
$valuetoshow = GETPOSTISSET('field-'.$object->element."-".$fieldname."-".$langcode) ? GETPOST('field-'.$object->element.'-'.$fieldname."-".$langcode, $check) : '';
|
||||
if (empty($valuetoshow)) {
|
||||
$object->fetchValueForAlternateLanguages();
|
||||
//var_dump($object->array_languages);
|
||||
@ -353,11 +353,11 @@ class Form
|
||||
$s=picto_from_langcode($conf->global->PDF_USE_ALSO_LANGUAGE_CODE, 'class="pictoforlang"');
|
||||
$result .= $s;
|
||||
if ($typeofdata == 'textarea') {
|
||||
$result .= '<textarea name="'.$fieldname."-".$langcode.'" id="'.$fieldname."-".$langcode.'" class="'.$morecss.'" rows="'.ROWS_2.'" wrap="soft">';
|
||||
$result .= $object->address;
|
||||
$result .= '<textarea name="field-'.$object->element."-".$fieldname."-".$langcode.'" id="'.$fieldname."-".$langcode.'" class="'.$morecss.'" rows="'.ROWS_2.'" wrap="soft">';
|
||||
$result .= $valuetoshow;
|
||||
$result .= '</textarea>';
|
||||
} else {
|
||||
$result .= '<input type="text" class="inputfieldforlang '.($morecss ? ' '.$morecss : '').'" name="'.$fieldname."-".$langcode.'" value="'.$valuetoshow.'">';
|
||||
$result .= '<input type="text" class="inputfieldforlang '.($morecss ? ' '.$morecss : '').'" name="field-'.$object->element.'-'.$fieldname.'-'.$langcode.'" value="'.$valuetoshow.'">';
|
||||
}
|
||||
$result .= '</div>';
|
||||
$result .= '<script>$(".image-'.$object->element.'-'.$fieldname.'").click(function() { console.log("Toggle lang widget"); jQuery(".field-'.$object->element.'-'.$fieldname.'").toggle(); });</script>';
|
||||
|
||||
@ -135,7 +135,6 @@ if (empty($reshook))
|
||||
if ($soc_origin_id <= 0)
|
||||
{
|
||||
$langs->load('errors');
|
||||
$langs->load('companies');
|
||||
setEventMessages($langs->trans('ErrorThirdPartyIdIsMandatory', $langs->transnoentitiesnoconv('MergeOriginThirdparty')), null, 'errors');
|
||||
}
|
||||
else
|
||||
@ -491,6 +490,14 @@ if (empty($reshook))
|
||||
$error++;
|
||||
}
|
||||
|
||||
// Fill array 'array_languages' with data from add form
|
||||
$ret = $object->setValuesForAlternateLanguages();
|
||||
if ($ret < 0)
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
//var_dump($object->array_languages);exit;
|
||||
|
||||
if (GETPOST('deletephoto')) $object->logo = '';
|
||||
elseif (!empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user