dolibarr 21.0.3
traduction.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
3 * Copyright (C) 2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
4 * Copyright (C) 2010-2016 Destailleur Laurent <eldy@users.sourceforge.net>
5 * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 * or see https://www.gnu.org/
22 */
23
30// Load Dolibarr environment
31require '../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
36require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
37
46// Load translation files required by the page
47$langs->loadLangs(array('categories', 'languages'));
48
49$id = GETPOSTINT('id');
50$label = GETPOST('label', 'alpha');
51$action = GETPOST('action', 'aZ09');
52$cancel = GETPOST('cancel', 'alpha');
53$langtodelete = GETPOST('langtodelete', 'alpha');
54
55if ($id == '' && $label == '') {
56 dol_print_error(null, 'Missing parameter id');
57 exit();
58}
59
60$object = new Categorie($db);
61$result = $object->fetch($id, $label);
62if ($result <= 0) {
63 dol_print_error($db, $object->error);
64 exit;
65}
66
67$type = $object->type;
68if (is_numeric($type)) {
69 $type = Categorie::$MAP_ID_TO_CODE[(int) $type]; // For backward compatibility
70}
71
72// Security check
73$result = restrictedArea($user, 'categorie', $id, '&category');
74
75$permissiontoadd = $user->hasRight('categorie', 'creer');
76
77
78/*
79 * Actions
80 */
81
82$error = 0;
83
84// return to translation view if cancelled
85if ($cancel == $langs->trans("Cancel")) {
86 $action = '';
87}
88
89// delete a translation
90if ($action == 'delete' && $langtodelete && $user->hasRight('categorie', 'creer')) {
91 $res = $object->delMultiLangs($langtodelete, $user);
92 if ($res < 0) {
93 setEventMessages($object->error, $object->errors, 'errors');
94 } else {
95 unset($object->multilangs[$langtodelete]);
96 setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
97 }
98 $action = '';
99}
100
101// validation of addition
102if ($action == 'vadd' && $cancel != $langs->trans("Cancel") && $permissiontoadd) {
103 $object->fetch($id);
104 $current_lang = $langs->getDefaultLang();
105
106 // check parameters
107 $forcelangprod = GETPOST('forcelangprod', 'alpha');
108 $libelle = GETPOST('libelle', 'alpha');
109 $desc = GETPOST('desc', 'restricthtml');
110
111 if (empty($forcelangprod)) {
112 $error++;
113 $object->errors[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Translation'));
114 }
115
116 if (!$error) {
117 if (empty($libelle)) {
118 $error++;
119 $object->errors[] = $langs->trans('Language_'.$forcelangprod).' : '.$langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Label'));
120 }
121
122 if (!$error) {
123 // update the object
124 if ($forcelangprod == $current_lang) {
125 $object->label = $libelle;
126 $object->description = dol_htmlcleanlastbr($desc);
127
128 $object->update($user);
129 } else {
130 $object->multilangs[$forcelangprod]["label"] = $libelle;
131 $object->multilangs[$forcelangprod]["description"] = dol_htmlcleanlastbr($desc);
132 }
133
134 // save in base / sauvegarde en base
135 $res = $object->setMultiLangs($user);
136 if ($res < 0) {
137 $error++;
138 }
139 }
140 }
141
142 if ($error) {
143 $action = 'add';
144 setEventMessages($object->error, $object->errors, 'errors');
145 } else {
146 $action = '';
147 }
148}
149
150// validation of the edition
151if ($action == 'vedit' && $cancel != $langs->trans("Cancel") && $permissiontoadd) {
152 $object->fetch($id);
153 $current_lang = $langs->getDefaultLang();
154
155 foreach ($object->multilangs as $key => $value) { // recording of new values in the object
156 $libelle = GETPOST('libelle-'.$key, 'alpha');
157 $desc = GETPOST('desc-'.$key, 'restricthtml');
158
159 if (empty($libelle)) {
160 $error++;
161 $object->errors[] = $langs->trans('Language_'.$key).' : '.$langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Label'));
162 }
163
164 if ($key == $current_lang) {
165 $object->label = $libelle;
166 $object->description = dol_htmlcleanlastbr($desc);
167 } else {
168 $object->multilangs[$key]["label"] = $libelle;
169 $object->multilangs[$key]["description"] = dol_htmlcleanlastbr($desc);
170 }
171 }
172
173 if (!$error) {
174 $res = $object->setMultiLangs($user);
175 if ($res < 0) {
176 $error++;
177 }
178 }
179
180 if ($error) {
181 $action = 'edit';
182 setEventMessages($object->error, $object->errors, 'errors');
183 } else {
184 $action = '';
185 }
186}
187
188
189/*
190 * View
191 */
192
193$form = new Form($db);
194$formadmin = new FormAdmin($db);
195$formother = new FormOther($db);
196
197llxHeader("", "", $langs->trans("Translation"));
198
199$title = Categorie::$MAP_TYPE_TITLE_AREA[$type];
200
201$head = categories_prepare_head($object, $type);
202
203// Calculate $cnt_trans
204$cnt_trans = 0;
205if (!empty($object->multilangs)) {
206 foreach ($object->multilangs as $key => $value) {
207 $cnt_trans++;
208 }
209}
210
211print dol_get_fiche_head($head, 'translation', $langs->trans($title), -1, 'category');
212
213$backtolist = (GETPOST('backtolist') ? GETPOST('backtolist') : DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.urlencode($type));
214$linkback = '<a href="'.dol_sanitizeUrl($backtolist).'">'.$langs->trans("BackToList").'</a>';
215$object->next_prev_filter = 'type:=:'.((int) $object->type);
216$object->ref = $object->label;
217$morehtmlref = '<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> ';
218$ways = $object->print_all_ways(" &gt;&gt; ", '', 1);
219foreach ($ways as $way) {
220 $morehtmlref .= $way."<br>\n";
221}
222$morehtmlref .= '</div>';
223
224dol_banner_tab($object, 'label', $linkback, ($user->socid ? 0 : 1), 'label', 'label', $morehtmlref, '&type='.$type, 0, '', '', 1);
225
226print '<br>';
227
228print '<div class="fichecenter">';
229print '<div class="underbanner clearboth"></div>';
230
231print '<table class="border centpercent tableforfield">';
232
233// Description
234print '<tr><td class="titlefield notopnoleft">';
235print $langs->trans("Description").'</td><td>';
236print dol_htmlentitiesbr($object->description);
237print '</td></tr>';
238
239// Color
240print '<tr><td class="notopnoleft">';
241print $langs->trans("Color").'</td><td>';
242print $formother->showColor($object->color);
243print '</td></tr>';
244
245print '</table>';
246print '</div>';
247
248print dol_get_fiche_end();
249
250
251
252/*
253 * Action bar
254 */
255
256print "\n<div class=\"tabsAction\">\n";
257
258if ($action == '') {
259 if ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer')) {
260 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=add&token='.newToken().'&id='.$object->id.'&type='.$type.'">'.$langs->trans('Add').'</a>';
261 if ($cnt_trans > 0) {
262 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&token='.newToken().'&id='.$object->id.'&type='.$type.'">'.$langs->trans('Update').'</a>';
263 }
264 }
265}
266
267print "\n</div>\n";
268
269
270
271if ($action == 'edit') {
272 // WYSIWYG Editor
273 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
274
275 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
276 print '<input type="hidden" name="token" value="'.newToken().'">';
277 print '<input type="hidden" name="action" value="vedit">';
278 print '<input type="hidden" name="id" value="'.$object->id.'">';
279 print '<input type="hidden" name="type" value="'.$type.'">';
280
281 if (!empty($object->multilangs)) {
282 foreach ($object->multilangs as $key => $value) {
283 print "<br><b><u>".$langs->trans('Language_'.$key)." :</u></b><br>";
284 print '<table class="border centpercent">';
285
286 // Label
287 $libelle = (GETPOST('libelle-'.$key, 'alpha') ? GETPOST('libelle-'.$key, 'alpha') : ($object->multilangs[$key]['label'] ?? ''));
288 print '<tr><td class="titlefield fieldrequired">'.$langs->trans('Label').'</td><td><input name="libelle-'.$key.'" size="40" value="'.$libelle.'"></td></tr>';
289
290 // Desc
291 $desc = (GETPOST('desc-'.$key) ? GETPOST('desc-'.$key) : ($object->multilangs[$key]['description'] ?? ''));
292 print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
293 $doleditor = new DolEditor("desc-$key", $desc, '', 160, 'dolibarr_notes', '', false, true, isModEnabled('fckeditor') && getDolGlobalInt('FCKEDITOR_ENABLE_SOCIETE'), ROWS_3, '90%');
294 $doleditor->Create();
295 print '</td></tr>';
296
297 print '</tr>';
298 print '</table>';
299 }
300 }
301
302 print '<br>';
303
304 print $form->buttonsSaveCancel();
305
306 print '</form>';
307} elseif ($action != 'add') {
308 if ($cnt_trans) {
309 print '<div class="underbanner clearboth"></div>';
310 }
311
312 if (!empty($object->multilangs)) {
313 foreach ($object->multilangs as $key => $value) {
314 $s = picto_from_langcode((string) $key);
315 print '<table class="border centpercent">';
316 print '<tr class="liste_titre"><td colspan="2">'.($s ? $s.' ' : '')." <b>".$langs->trans('Language_'.$key).":</b> ".'<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'&langtodelete='.$key.'&type='.$type.'">'.img_delete('', '').'</a></td></tr>';
317 print '<tr><td class="titlefield">'.$langs->trans('Label').'</td><td>'.($object->multilangs[$key]["label"] ?? '').'</td></tr>';
318 print '<tr><td>'.$langs->trans('Description').'</td><td>'.($object->multilangs[$key]["description"] ?? '').'</td></tr>';
319 if (getDolGlobalString('CATEGORY_USE_OTHER_FIELD_IN_TRANSLATION')) {
320 print '<tr><td>'.$langs->trans('Other').' ('.$langs->trans("NotYetAvailable").')</td><td>'.($object->multilangs[$key]["other"] ?? '').'</td></tr>';
321 }
322 print '</table>';
323 }
324 }
325 if (!$cnt_trans && $action != 'add') {
326 print '<div class="opacitymedium">'.$langs->trans('NoTranslation').'</div>';
327 }
328}
329
330
331/*
332 * Form to add a new translation
333 */
334
335if ($action == 'add' && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
336 //WYSIWYG Editor
337 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
338
339 print '<br>';
340 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
341 print '<input type="hidden" name="token" value="'.newToken().'">';
342 print '<input type="hidden" name="action" value="vadd">';
343 print '<input type="hidden" name="id" value="'.$id.'">';
344 print '<input type="hidden" name="type" value="'.$type.'">';
345
346 print '<table class="border centpercent">';
347 print '<tr><td class="titlefield fieldrequired">'.$langs->trans('Translation').'</td><td>';
348 print $formadmin->select_language(GETPOST('forcelangprod', 'alpha'), 'forcelangprod', 0, $object->multilangs);
349 print '</td></tr>';
350 print '<tr><td class="fieldrequired">'.$langs->trans('Label').'</td>';
351 print '<td><input name="libelle" class="minwidth200 maxwidth300" value="'.GETPOST('libelle', 'alpha').'"></td></tr>';
352 print '<tr><td>'.$langs->trans('Description').'</td><td>';
353 $doleditor = new DolEditor('desc', GETPOST('desc', 'restricthtml'), '', 160, 'dolibarr_notes', '', false, true, isModEnabled('fckeditor') && getDolGlobalInt('FCKEDITOR_ENABLE_SOCIETE'), ROWS_3, '90%');
354 $doleditor->Create();
355 print '</td></tr>';
356
357 print '</tr>';
358 print '</table>';
359
360 print $form->buttonsSaveCancel();
361
362 print '</form>';
363
364 print '<br>';
365}
366
367// End of page
368llxFooter();
369$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
categories_prepare_head(Categorie $object, $type)
Prepare array with list of tabs.
Class to manage categories.
Class to manage a WYSIWYG editor.
Class to generate html code for admin pages.
Class to manage generation of HTML components Only common components must be here.
Class permettant la generation de composants html autre Only common components are here.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.