dolibarr  13.0.2
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)) return array();
87 
88  if ($elementtype == 'thirdparty') $elementtype = 'societe';
89  if ($elementtype == 'contact') $elementtype = 'socpeople';
90  if ($elementtype == 'order_supplier') $elementtype = 'commande_fournisseur';
91 
92 
93  $array_name_label = array();
94  if (!empty($conf->global->MAIN_USE_ALTERNATE_TRANSLATION_FOR)) {
95  $tmpelement = explode(';', $conf->global->MAIN_USE_ALTERNATE_TRANSLATION_FOR);
96  foreach ($tmpelement as $elementstring) {
97  $reg = array();
98  preg_match('/^(.*):(.*)$/', $elementstring, $reg);
99  $element = $reg[1];
100  $array_name_label[$element] = array();
101  $tmpfields = explode(',', $reg[2]);
102  foreach ($tmpfields as $field) {
103  //var_dump($fields);
104  //$tmpkeyvar = explode(':', $fields);
105  //$array_name_label[$element][$tmpkeyvar[0]] = $tmpkeyvar[1];
106  $array_name_label[$element][$field] = $field;
107  }
108  }
109  }
110  //var_dump($array_name_label);
111  $this->attributes = $array_name_label;
112 
113  return $array_name_label;
114  }
115 
116 
132  public function showInputField($key, $value, $extrafieldsobjectkey, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = '', $objectid = 0, $mode = 0)
133  {
134  global $conf, $langs, $form;
135 
136  if (!is_object($form))
137  {
138  require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
139  $form = new Form($this->db);
140  }
141 
142  $out = '';
143 
144  if (!preg_match('/options_$/', $keyprefix)) // Because we work on extrafields, we add 'options_' to prefix if not already added
145  {
146  $keyprefix = $keyprefix.'options_';
147  }
148 
149  return $out;
150  }
151 
152 
162  public function showOutputField($key, $value, $extrafieldsobjectkey, $moreparam = '')
163  {
164  global $conf, $langs;
165 
166  $out = $this->attributes[$extrafieldsobjectkey][$key];
167 
168  return $out;
169  }
170 }
showOutputField($key, $value, $extrafieldsobjectkey, $moreparam= '')
Return HTML string to put an output field into a page.
$conf db
API class for accounts.
Definition: inc.php:54
fetch_name_extralanguages($elementtype, $forceload=false)
Load array this-&gt;attributes with list of fields per object that need an alternate translation...
Class to manage generation of HTML components Only common components must be here.
Class to manage standard extra languages.
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.