dolibarr 21.0.0-beta
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 } else {
128 $object->multilangs[$forcelangprod]["label"] = $libelle;
129 $object->multilangs[$forcelangprod]["description"] = dol_htmlcleanlastbr($desc);
130 }
131
132 // save in base / sauvegarde en base
133 $res = $object->setMultiLangs($user);
134 if ($res < 0) {
135 $error++;
136 }
137 }
138 }
139
140 if ($error) {
141 $action = 'add';
142 setEventMessages($object->error, $object->errors, 'errors');
143 } else {
144 $action = '';
145 }
146}
147
148// validation of the edition
149if ($action == 'vedit' && $cancel != $langs->trans("Cancel") && $permissiontoadd) {
150 $object->fetch($id);
151 $current_lang = $langs->getDefaultLang();
152
153 foreach ($object->multilangs as $key => $value) { // recording of new values in the object
154 $libelle = GETPOST('libelle-'.$key, 'alpha');
155 $desc = GETPOST('desc-'.$key, 'restricthtml');
156
157 if (empty($libelle)) {
158 $error++;
159 $object->errors[] = $langs->trans('Language_'.$key).' : '.$langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Label'));
160 }
161
162 if ($key == $current_lang) {
163 $object->label = $libelle;
164 $object->description = dol_htmlcleanlastbr($desc);
165 } else {
166 $object->multilangs[$key]["label"] = $libelle;
167 $object->multilangs[$key]["description"] = dol_htmlcleanlastbr($desc);
168 }
169 }
170
171 if (!$error) {
172 $res = $object->setMultiLangs($user);
173 if ($res < 0) {
174 $error++;
175 }
176 }
177
178 if ($error) {
179 $action = 'edit';
180 setEventMessages($object->error, $object->errors, 'errors');
181 } else {
182 $action = '';
183 }
184}
185
186
187/*
188 * View
189 */
190
191$form = new Form($db);
192$formadmin = new FormAdmin($db);
193$formother = new FormOther($db);
194
195llxHeader("", "", $langs->trans("Translation"));
196
197$title = Categorie::$MAP_TYPE_TITLE_AREA[$type];
198
199$head = categories_prepare_head($object, $type);
200
201// Calculate $cnt_trans
202$cnt_trans = 0;
203if (!empty($object->multilangs)) {
204 foreach ($object->multilangs as $key => $value) {
205 $cnt_trans++;
206 }
207}
208
209print dol_get_fiche_head($head, 'translation', $langs->trans($title), -1, 'category');
210
211$backtolist = (GETPOST('backtolist') ? GETPOST('backtolist') : DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.urlencode($type));
212$linkback = '<a href="'.dol_sanitizeUrl($backtolist).'">'.$langs->trans("BackToList").'</a>';
213$object->next_prev_filter = 'type:=:'.((int) $object->type);
214$object->ref = $object->label;
215$morehtmlref = '<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> ';
216$ways = $object->print_all_ways(" &gt;&gt; ", '', 1);
217foreach ($ways as $way) {
218 $morehtmlref .= $way."<br>\n";
219}
220$morehtmlref .= '</div>';
221
222dol_banner_tab($object, 'label', $linkback, ($user->socid ? 0 : 1), 'label', 'label', $morehtmlref, '&type='.$type, 0, '', '', 1);
223
224print '<br>';
225
226print '<div class="fichecenter">';
227print '<div class="underbanner clearboth"></div>';
228
229print '<table class="border centpercent tableforfield">';
230
231// Description
232print '<tr><td class="titlefield notopnoleft">';
233print $langs->trans("Description").'</td><td>';
234print dol_htmlentitiesbr($object->description);
235print '</td></tr>';
236
237// Color
238print '<tr><td class="notopnoleft">';
239print $langs->trans("Color").'</td><td>';
240print $formother->showColor($object->color);
241print '</td></tr>';
242
243print '</table>';
244print '</div>';
245
246print dol_get_fiche_end();
247
248
249
250/*
251 * Action bar
252 */
253
254print "\n<div class=\"tabsAction\">\n";
255
256if ($action == '') {
257 if ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer')) {
258 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=add&token='.newToken().'&id='.$object->id.'&type='.$type.'">'.$langs->trans('Add').'</a>';
259 if ($cnt_trans > 0) {
260 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&token='.newToken().'&id='.$object->id.'&type='.$type.'">'.$langs->trans('Update').'</a>';
261 }
262 }
263}
264
265print "\n</div>\n";
266
267
268
269if ($action == 'edit') {
270 // WYSIWYG Editor
271 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
272
273 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
274 print '<input type="hidden" name="token" value="'.newToken().'">';
275 print '<input type="hidden" name="action" value="vedit">';
276 print '<input type="hidden" name="id" value="'.$object->id.'">';
277 print '<input type="hidden" name="type" value="'.$type.'">';
278
279 if (!empty($object->multilangs)) {
280 foreach ($object->multilangs as $key => $value) {
281 print "<br><b><u>".$langs->trans('Language_'.$key)." :</u></b><br>";
282 print '<table class="border centpercent">';
283
284 // Label
285 $libelle = (GETPOST('libelle-'.$key, 'alpha') ? GETPOST('libelle-'.$key, 'alpha') : ($object->multilangs[$key]['label'] ?? ''));
286 print '<tr><td class="titlefield fieldrequired">'.$langs->trans('Label').'</td><td><input name="libelle-'.$key.'" size="40" value="'.$libelle.'"></td></tr>';
287
288 // Desc
289 $desc = (GETPOST('desc-'.$key) ? GETPOST('desc-'.$key) : ($object->multilangs[$key]['description'] ?? ''));
290 print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
291 $doleditor = new DolEditor("desc-$key", $desc, '', 160, 'dolibarr_notes', '', false, true, isModEnabled('fckeditor') && getDolGlobalInt('FCKEDITOR_ENABLE_SOCIETE'), ROWS_3, '90%');
292 $doleditor->Create();
293 print '</td></tr>';
294
295 print '</tr>';
296 print '</table>';
297 }
298 }
299
300 print '<br>';
301
302 print $form->buttonsSaveCancel();
303
304 print '</form>';
305} elseif ($action != 'add') {
306 if ($cnt_trans) {
307 print '<div class="underbanner clearboth"></div>';
308 }
309
310 if (!empty($object->multilangs)) {
311 foreach ($object->multilangs as $key => $value) {
312 $s = picto_from_langcode((string) $key);
313 print '<table class="border centpercent">';
314 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>';
315 print '<tr><td class="titlefield">'.$langs->trans('Label').'</td><td>'.($object->multilangs[$key]["label"] ?? '').'</td></tr>';
316 print '<tr><td>'.$langs->trans('Description').'</td><td>'.($object->multilangs[$key]["description"] ?? '').'</td></tr>';
317 if (getDolGlobalString('CATEGORY_USE_OTHER_FIELD_IN_TRANSLATION')) {
318 print '<tr><td>'.$langs->trans('Other').' ('.$langs->trans("NotYetAvailable").')</td><td>'.($object->multilangs[$key]["other"] ?? '').'</td></tr>';
319 }
320 print '</table>';
321 }
322 }
323 if (!$cnt_trans && $action != 'add') {
324 print '<div class="opacitymedium">'.$langs->trans('NoTranslation').'</div>';
325 }
326}
327
328
329/*
330 * Form to add a new translation
331 */
332
333if ($action == 'add' && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
334 //WYSIWYG Editor
335 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
336
337 print '<br>';
338 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
339 print '<input type="hidden" name="token" value="'.newToken().'">';
340 print '<input type="hidden" name="action" value="vadd">';
341 print '<input type="hidden" name="id" value="'.$id.'">';
342 print '<input type="hidden" name="type" value="'.$type.'">';
343
344 print '<table class="border centpercent">';
345 print '<tr><td class="titlefield fieldrequired">'.$langs->trans('Translation').'</td><td>';
346 print $formadmin->select_language(GETPOST('forcelangprod', 'alpha'), 'forcelangprod', 0, $object->multilangs);
347 print '</td></tr>';
348 print '<tr><td class="fieldrequired">'.$langs->trans('Label').'</td>';
349 print '<td><input name="libelle" class="minwidth200 maxwidth300" value="'.GETPOST('libelle', 'alpha').'"></td></tr>';
350 print '<tr><td>'.$langs->trans('Description').'</td><td>';
351 $doleditor = new DolEditor('desc', GETPOST('desc', 'restricthtml'), '', 160, 'dolibarr_notes', '', false, true, isModEnabled('fckeditor') && getDolGlobalInt('FCKEDITOR_ENABLE_SOCIETE'), ROWS_3, '90%');
352 $doleditor->Create();
353 print '</td></tr>';
354
355 print '</tr>';
356 print '</table>';
357
358 print $form->buttonsSaveCancel();
359
360 print '</form>';
361
362 print '<br>';
363}
364
365// End of page
366llxFooter();
367$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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.
llxFooter()
Footer empty.
Definition document.php:107
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.