dolibarr 21.0.0-alpha
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 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 * or see https://www.gnu.org/
21 */
22
29// Load Dolibarr environment
30require '../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
36
37// Load translation files required by the page
38$langs->loadLangs(array('categories', 'languages'));
39
40$id = GETPOSTINT('id');
41$label = GETPOST('label', 'alpha');
42$action = GETPOST('action', 'aZ09');
43$cancel = GETPOST('cancel', 'alpha');
44$langtodelete = GETPOST('langtodelete', 'alpha');
45
46if ($id == '' && $label == '') {
47 dol_print_error(null, 'Missing parameter id');
48 exit();
49}
50
51$object = new Categorie($db);
52$result = $object->fetch($id, $label);
53if ($result <= 0) {
54 dol_print_error($db, $object->error);
55 exit;
56}
57
58$type = $object->type;
59if (is_numeric($type)) {
60 $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
61}
62
63// Security check
64$result = restrictedArea($user, 'categorie', $id, '&category');
65
66$permissiontoadd = $user->hasRight('categorie', 'creer');
67
68
69/*
70 * Actions
71 */
72
73$error = 0;
74
75// return to translation view if cancelled
76if ($cancel == $langs->trans("Cancel")) {
77 $action = '';
78}
79
80// delete a translation
81if ($action == 'delete' && $langtodelete && $user->hasRight('categorie', 'creer')) {
82 $res = $object->delMultiLangs($langtodelete, $user);
83 if ($res < 0) {
84 setEventMessages($object->error, $object->errors, 'errors');
85 } else {
86 unset($object->multilangs[$langtodelete]);
87 setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
88 }
89 $action = '';
90}
91
92// validation of addition
93if ($action == 'vadd' && $cancel != $langs->trans("Cancel") && $permissiontoadd) {
94 $object->fetch($id);
95 $current_lang = $langs->getDefaultLang();
96
97 // check parameters
98 $forcelangprod = GETPOST('forcelangprod', 'alpha');
99 $libelle = GETPOST('libelle', 'alpha');
100 $desc = GETPOST('desc', 'restricthtml');
101
102 if (empty($forcelangprod)) {
103 $error++;
104 $object->errors[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Translation'));
105 }
106
107 if (!$error) {
108 if (empty($libelle)) {
109 $error++;
110 $object->errors[] = $langs->trans('Language_'.$forcelangprod).' : '.$langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Label'));
111 }
112
113 if (!$error) {
114 // update the object
115 if ($forcelangprod == $current_lang) {
116 $object->label = $libelle;
117 $object->description = dol_htmlcleanlastbr($desc);
118 } else {
119 $object->multilangs[$forcelangprod]["label"] = $libelle;
120 $object->multilangs[$forcelangprod]["description"] = dol_htmlcleanlastbr($desc);
121 }
122
123 // save in base / sauvegarde en base
124 $res = $object->setMultiLangs($user);
125 if ($res < 0) {
126 $error++;
127 }
128 }
129 }
130
131 if ($error) {
132 $action = 'add';
133 setEventMessages($object->error, $object->errors, 'errors');
134 } else {
135 $action = '';
136 }
137}
138
139// validation of the edition
140if ($action == 'vedit' && $cancel != $langs->trans("Cancel") && $permissiontoadd) {
141 $object->fetch($id);
142 $current_lang = $langs->getDefaultLang();
143
144 foreach ($object->multilangs as $key => $value) { // recording of new values in the object
145 $libelle = GETPOST('libelle-'.$key, 'alpha');
146 $desc = GETPOST('desc-'.$key, 'restricthtml');
147
148 if (empty($libelle)) {
149 $error++;
150 $object->errors[] = $langs->trans('Language_'.$key).' : '.$langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Label'));
151 }
152
153 if ($key == $current_lang) {
154 $object->label = $libelle;
155 $object->description = dol_htmlcleanlastbr($desc);
156 } else {
157 $object->multilangs[$key]["label"] = $libelle;
158 $object->multilangs[$key]["description"] = dol_htmlcleanlastbr($desc);
159 }
160 }
161
162 if (!$error) {
163 $res = $object->setMultiLangs($user);
164 if ($res < 0) {
165 $error++;
166 }
167 }
168
169 if ($error) {
170 $action = 'edit';
171 setEventMessages($object->error, $object->errors, 'errors');
172 } else {
173 $action = '';
174 }
175}
176
177
178/*
179 * View
180 */
181
182$form = new Form($db);
183$formadmin = new FormAdmin($db);
184$formother = new FormOther($db);
185
186llxHeader("", "", $langs->trans("Translation"));
187
188$title = Categorie::$MAP_TYPE_TITLE_AREA[$type];
189
190$head = categories_prepare_head($object, $type);
191
192// Calculate $cnt_trans
193$cnt_trans = 0;
194if (!empty($object->multilangs)) {
195 foreach ($object->multilangs as $key => $value) {
196 $cnt_trans++;
197 }
198}
199
200print dol_get_fiche_head($head, 'translation', $langs->trans($title), -1, 'category');
201
202$backtolist = (GETPOST('backtolist') ? GETPOST('backtolist') : DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.urlencode($type));
203$linkback = '<a href="'.dol_sanitizeUrl($backtolist).'">'.$langs->trans("BackToList").'</a>';
204$object->next_prev_filter = 'type = '.((int) $object->type);
205$object->ref = $object->label;
206$morehtmlref = '<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> ';
207$ways = $object->print_all_ways(" &gt;&gt; ", '', 1);
208foreach ($ways as $way) {
209 $morehtmlref .= $way."<br>\n";
210}
211$morehtmlref .= '</div>';
212
213dol_banner_tab($object, 'label', $linkback, ($user->socid ? 0 : 1), 'label', 'label', $morehtmlref, '&type='.$type, 0, '', '', 1);
214
215print '<br>';
216
217print '<div class="fichecenter">';
218print '<div class="underbanner clearboth"></div>';
219
220print '<table class="border centpercent tableforfield">';
221
222// Description
223print '<tr><td class="titlefield notopnoleft">';
224print $langs->trans("Description").'</td><td>';
225print dol_htmlentitiesbr($object->description);
226print '</td></tr>';
227
228// Color
229print '<tr><td class="notopnoleft">';
230print $langs->trans("Color").'</td><td>';
231print $formother->showColor($object->color);
232print '</td></tr>';
233
234print '</table>';
235print '</div>';
236
237print dol_get_fiche_end();
238
239
240
241/*
242 * Action bar
243 */
244
245print "\n<div class=\"tabsAction\">\n";
246
247if ($action == '') {
248 if ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer')) {
249 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=add&token='.newToken().'&id='.$object->id.'&type='.$type.'">'.$langs->trans('Add').'</a>';
250 if ($cnt_trans > 0) {
251 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&token='.newToken().'&id='.$object->id.'&type='.$type.'">'.$langs->trans('Update').'</a>';
252 }
253 }
254}
255
256print "\n</div>\n";
257
258
259
260if ($action == 'edit') {
261 // WYSIWYG Editor
262 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
263
264 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
265 print '<input type="hidden" name="token" value="'.newToken().'">';
266 print '<input type="hidden" name="action" value="vedit">';
267 print '<input type="hidden" name="id" value="'.$object->id.'">';
268 print '<input type="hidden" name="type" value="'.$type.'">';
269
270 if (!empty($object->multilangs)) {
271 foreach ($object->multilangs as $key => $value) {
272 print "<br><b><u>".$langs->trans('Language_'.$key)." :</u></b><br>";
273 print '<table class="border centpercent">';
274
275 // Label
276 $libelle = (GETPOST('libelle-'.$key, 'alpha') ? GETPOST('libelle-'.$key, 'alpha') : ($object->multilangs[$key]['label'] ?? ''));
277 print '<tr><td class="titlefield fieldrequired">'.$langs->trans('Label').'</td><td><input name="libelle-'.$key.'" size="40" value="'.$libelle.'"></td></tr>';
278
279 // Desc
280 $desc = (GETPOST('desc-'.$key) ? GETPOST('desc-'.$key) : ($object->multilangs[$key]['description'] ?? ''));
281 print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
282 $doleditor = new DolEditor("desc-$key", $desc, '', 160, 'dolibarr_notes', '', false, true, isModEnabled('fckeditor') && getDolGlobalInt('FCKEDITOR_ENABLE_SOCIETE'), ROWS_3, '90%');
283 $doleditor->Create();
284 print '</td></tr>';
285
286 print '</tr>';
287 print '</table>';
288 }
289 }
290
291 print '<br>';
292
293 print $form->buttonsSaveCancel();
294
295 print '</form>';
296} elseif ($action != 'add') {
297 if ($cnt_trans) {
298 print '<div class="underbanner clearboth"></div>';
299 }
300
301 if (!empty($object->multilangs)) {
302 foreach ($object->multilangs as $key => $value) {
303 $s = picto_from_langcode((string) $key);
304 print '<table class="border centpercent">';
305 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>';
306 print '<tr><td class="titlefield">'.$langs->trans('Label').'</td><td>'.($object->multilangs[$key]["label"] ?? '').'</td></tr>';
307 print '<tr><td>'.$langs->trans('Description').'</td><td>'.($object->multilangs[$key]["description"] ?? '').'</td></tr>';
308 if (getDolGlobalString('CATEGORY_USE_OTHER_FIELD_IN_TRANSLATION')) {
309 print '<tr><td>'.$langs->trans('Other').' ('.$langs->trans("NotYetAvailable").')</td><td>'.($object->multilangs[$key]["other"] ?? '').'</td></tr>';
310 }
311 print '</table>';
312 }
313 }
314 if (!$cnt_trans && $action != 'add') {
315 print '<div class="opacitymedium">'.$langs->trans('NoTranslation').'</div>';
316 }
317}
318
319
320/*
321 * Form to add a new translation
322 */
323
324if ($action == 'add' && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
325 //WYSIWYG Editor
326 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
327
328 print '<br>';
329 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
330 print '<input type="hidden" name="token" value="'.newToken().'">';
331 print '<input type="hidden" name="action" value="vadd">';
332 print '<input type="hidden" name="id" value="'.$id.'">';
333 print '<input type="hidden" name="type" value="'.$type.'">';
334
335 print '<table class="border centpercent">';
336 print '<tr><td class="titlefield fieldrequired">'.$langs->trans('Translation').'</td><td>';
337 print $formadmin->select_language(GETPOST('forcelangprod', 'alpha'), 'forcelangprod', 0, $object->multilangs);
338 print '</td></tr>';
339 print '<tr><td class="fieldrequired">'.$langs->trans('Label').'</td>';
340 print '<td><input name="libelle" class="minwidth200 maxwidth300" value="'.GETPOST('libelle', 'alpha').'"></td></tr>';
341 print '<tr><td>'.$langs->trans('Description').'</td><td>';
342 $doleditor = new DolEditor('desc', GETPOST('desc', 'restricthtml'), '', 160, 'dolibarr_notes', '', false, true, isModEnabled('fckeditor') && getDolGlobalInt('FCKEDITOR_ENABLE_SOCIETE'), ROWS_3, '90%');
343 $doleditor->Create();
344 print '</td></tr>';
345
346 print '</tr>';
347 print '</table>';
348
349 print $form->buttonsSaveCancel();
350
351 print '</form>';
352
353 print '<br>';
354}
355
356// End of page
357llxFooter();
358$db->close();
$id
Definition account.php:39
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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:70
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.