Work on extralanguages

This commit is contained in:
Laurent Destailleur 2020-04-01 23:15:53 +02:00
parent 184d50171d
commit 6aea67a5b9
4 changed files with 1400 additions and 59 deletions

View File

@ -629,7 +629,7 @@ abstract class CommonObject
*/
public function getBannerAddress($htmlkey, $object)
{
global $conf, $langs, $form;
global $conf, $langs, $form, $extralanguages;
$countriesusingstate = array('AU', 'US', 'IN', 'GB', 'ES', 'UK', 'TR'); // See also option MAIN_FORCE_STATE_INTO_ADDRESS
@ -673,18 +673,24 @@ abstract class CommonObject
$out .= dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', '); $outdone++;
$outdone++;
$useextralanguages = $conf->global->PDF_USE_ALSO_LANGUAGE_CODE;
if ($useextralanguages) {
$this->fetchValuesForExtraLanguages();
$extralanguages = array();
if (isset($this->array_languages['address'])) $extralanguages[] = reset(array_keys($this->array_languages['address']));
if (isset($this->array_languages['town'])) $extralanguages[] = reset(array_keys($this->array_languages['town']));
// 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($extralanguages) && count($extralanguages)) {
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 (! empty($extralanguages->attributes['societe']['address']) || ! empty($extralanguages->attributes['societe']['town']))
{
$this->fetchValuesForExtraLanguages();
if (! is_object($form)) $form = new Form($this->db);
$htmltext = '';
// If there is extra languages
foreach($extralanguages as $key => $extralangcode) {
foreach($arrayoflangcode as $extralangcode) {
$s=picto_from_langcode($extralangcode, 'class="pictoforlang paddingright"');
$coords = $this->getFullAddress(1, ', ', $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT, $extralangcode);
$htmltext .= $s.dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', ');

View File

@ -842,7 +842,7 @@ class ExtraFields
/**
* Load array this->attributes, or old this->attribute_xxx like attribute_label, attribute_type, ...
*
* @param string $elementtype Type of element ('adherent', 'commande', 'thirdparty', 'facture', 'propal', 'product', ...).
* @param string $elementtype Type of element ('' = all, 'adherent', 'commande', 'thirdparty', 'facture', 'propal', 'product', ...).
* @param boolean $forceload Force load of extra fields whatever is status of cache.
* @return array Array of attributes keys+label for all extra fields.
*/
@ -859,30 +859,6 @@ class ExtraFields
$array_name_label = array();
// To avoid conflicts with external modules. TODO Remove this.
if (empty($forceload) && !empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return $array_name_label;
// If already loaded
// TODO Enable this cache test
// if (empty($forceload) && ! empty($this->attributes[$tab->elementtype]['loaded'])) return $array_name_label;
// Set array of label of entity
// Remove completely loading of label. This should be done by presentation.
/*
$labelmulticompany=array();
if (!empty($conf->multicompany->enabled))
{
$sql_entity_name='SELECT rowid, label FROM '.MAIN_DB_PREFIX.'entity WHERE rowid in (0,'.$conf->entity.')';
$resql_entity_name=$this->db->query($sql_entity_name);
if ($resql_entity_name)
{
while ($obj = $this->db->fetch_object($resql_entity_name))
{
$labelmulticompany[$obj->rowid]=$obj->label;
}
}
}*/
// We should not have several time this request. If we have, there is some optimization to do by calling a simple $extrafields->fetch_optionals() in top of code and not into subcode
$sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,langs,list,printable,totalizable,fielddefault,fieldcomputed,entity,enabled,help";
$sql .= " FROM ".MAIN_DB_PREFIX."extrafields";

File diff suppressed because it is too large Load Diff

View File

@ -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 .='<div class="inline-block paddingleft image-'.$object->element.'-'.$fieldname.'">';
$s=img_picto($langs->trans("ShowOtherLanguages"), 'language', '', false, 0, 0, '', 'fa-15 editfieldlang');
@ -343,22 +355,28 @@ class Form
$result .='<div class="inline-block hidden field-'.$object->element.'-'.$fieldname.'">';
$valuetoshow = GETPOSTISSET('field-'.$object->element."-".$fieldname."-".$langcode) ? GETPOST('field-'.$object->element.'-'.$fieldname."-".$langcode, $check) : '';
if (empty($valuetoshow)) {
$object->fetchValuesForExtraLanguages();
//var_dump($object->array_languages);
$valuetoshow = $object->array_languages[$fieldname][$langcode];
}
$resultforextrlang = '';
foreach($arrayoflangcode as $langcode)
{
$valuetoshow = GETPOSTISSET('field-'.$object->element."-".$fieldname."-".$langcode) ? GETPOST('field-'.$object->element.'-'.$fieldname."-".$langcode, $check) : '';
if (empty($valuetoshow)) {
$object->fetchValuesForExtraLanguages();
//var_dump($object->array_languages);
$valuetoshow = $object->array_languages[$fieldname][$langcode];
}
$s=picto_from_langcode($conf->global->PDF_USE_ALSO_LANGUAGE_CODE, 'class="pictoforlang paddingright"');
$result .= $s;
if ($typeofdata == 'textarea') {
$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="field-'.$object->element.'-'.$fieldname.'-'.$langcode.'" value="'.$valuetoshow.'">';
$s=picto_from_langcode($langcode, 'class="pictoforlang paddingright"');
$resultforextrlang .= $s;
if ($typeofdata == 'textarea') {
$resultforextrlang .= '<textarea name="field-'.$object->element."-".$fieldname."-".$langcode.'" id="'.$fieldname."-".$langcode.'" class="'.$morecss.'" rows="'.ROWS_2.'" wrap="soft">';
$resultforextrlang .= $valuetoshow;
$resultforextrlang .= '</textarea>';
} else {
$resultforextrlang .= '<input type="text" class="inputfieldforlang '.($morecss ? ' '.$morecss : '').'" name="field-'.$object->element.'-'.$fieldname.'-'.$langcode.'" value="'.$valuetoshow.'">';
}
}
$result .= $resultforextrlang;
$result .= '</div>';
$result .= '<script>$(".image-'.$object->element.'-'.$fieldname.'").click(function() { console.log("Toggle lang widget"); jQuery(".field-'.$object->element.'-'.$fieldname.'").toggle(); });</script>';
}
@ -7260,7 +7278,7 @@ class Form
*/
public function showrefnav($object, $paramid, $morehtml = '', $shownav = 1, $fieldid = 'rowid', $fieldref = 'ref', $morehtmlref = '', $moreparam = '', $nodbprefix = 0, $morehtmlleft = '', $morehtmlstatus = '', $morehtmlright = '')
{
global $langs, $conf, $hookmanager;
global $langs, $conf, $hookmanager, $extralanguages;
$ret = '';
if (empty($fieldid)) $fieldid = 'rowid';
@ -7360,16 +7378,24 @@ class Form
{
$ret .= dol_htmlentities($object->name);
$useextralanguages = $conf->global->PDF_USE_ALSO_LANGUAGE_CODE;
if ($useextralanguages) {
$object->fetchValuesForExtraLanguages();
$extralanguages = array();
if (isset($object->array_languages['name'])) $extralanguages[] = reset(array_keys($object->array_languages['name']));
// 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 (! empty($extralanguages->attributes['societe']['name']))
{
$object->fetchValuesForExtraLanguages();
if (is_array($extralanguages) && count($extralanguages)) {
$htmltext = '';
// If there is extra languages
foreach($extralanguages as $extralangcode) {
foreach($arrayoflangcode as $extralangcode) {
$s=picto_from_langcode($extralangcode, 'class="pictoforlang paddingright"');
$htmltext .= $s.$object->array_languages['name'][$extralangcode];
}