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