dolibarr 21.0.0-alpha
extralanguages.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2020 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
30{
34 public $db;
35
39 public $attributes;
40
44 public $error = '';
45
49 public $errors = array();
50
54 public $errno;
55
56
62 public function __construct($db)
63 {
64 $this->db = $db;
65 $this->error = '';
66 $this->errors = array();
67 $this->attributes = array();
68 }
69
70
71 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
82 public function fetch_name_extralanguages($elementtype, $forceload = false)
83 {
84 // phpcs:enable
85 global $conf;
86
87 if (empty($elementtype)) {
88 return array();
89 }
90
91 if ($elementtype == 'thirdparty') {
92 $elementtype = 'societe';
93 }
94 if ($elementtype == 'contact') {
95 $elementtype = 'socpeople';
96 }
97 if ($elementtype == 'order_supplier') {
98 $elementtype = 'commande_fournisseur';
99 }
100
101
102 $array_name_label = array();
103 if (getDolGlobalString('MAIN_USE_ALTERNATE_TRANSLATION_FOR')) {
104 $tmpelement = explode(';', getDolGlobalString('MAIN_USE_ALTERNATE_TRANSLATION_FOR'));
105 foreach ($tmpelement as $elementstring) {
106 $reg = array();
107 preg_match('/^(.*):(.*)$/', $elementstring, $reg);
108 $element = $reg[1];
109 $array_name_label[$element] = array();
110 $tmpfields = explode(',', $reg[2]);
111 foreach ($tmpfields as $field) {
112 //var_dump($fields);
113 //$tmpkeyvar = explode(':', $fields);
114 //$array_name_label[$element][$tmpkeyvar[0]] = $tmpkeyvar[1];
115 $array_name_label[$element][$field] = $field;
116 }
117 }
118 }
119 //var_dump($array_name_label);
120 $this->attributes = $array_name_label;
121
122 return $array_name_label;
123 }
124
125
141 public function showInputField($key, $value, $extrafieldsobjectkey, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = '', $objectid = 0, $mode = 0)
142 {
143 global $conf, $langs, $form;
144
145 if (!is_object($form)) {
146 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
147 $form = new Form($this->db);
148 }
149
150 $out = '';
151
152 if (!preg_match('/options_$/', $keyprefix)) { // Because we work on extrafields, we add 'options_' to prefix if not already added
153 $keyprefix .= 'options_';
154 }
155
156 return $out;
157 }
158
159
169 public function showOutputField($key, $value, $extrafieldsobjectkey, $moreparam = '')
170 {
171 global $conf, $langs;
172
173 $out = $this->attributes[$extrafieldsobjectkey][$key];
174
175 return $out;
176 }
177}
Class to manage standard extra languages.
showOutputField($key, $value, $extrafieldsobjectkey, $moreparam='')
Return HTML string to put an output field into a page.
fetch_name_extralanguages($elementtype, $forceload=false)
Load array this->attributes with list of fields per object that need an alternate translation.
showInputField($key, $value, $extrafieldsobjectkey, $moreparam='', $keysuffix='', $keyprefix='', $morecss='', $objectid=0, $mode=0)
Return HTML string to put an input field into a page Code very similar with showInputField of common ...
__construct($db)
Constructor.
Class to manage generation of HTML components Only common components must be here.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.