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
45if ($id == '' && $label == '') {
46 dol_print_error(null, 'Missing parameter id');
47 exit();
48}
49
50$object = new Categorie($db);
51$result = $object->fetch($id, $label);
52if ($result <= 0) {
53 dol_print_error($db, $object->error);
54 exit;
55}
56
57$type = $object->type;
58if (is_numeric($type)) {
59 $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
60}
61
62// Security check
63$result = restrictedArea($user, 'categorie', $id, '&category');
64
65$permissiontoadd = $user->hasRight('categorie', 'creer');
66
67
68/*
69 * Actions
70 */
71
72$error = 0;
73
74// return to translation view if cancelled
75if ($cancel == $langs->trans("Cancel")) {
76 $action = '';
77}
78
79
80// validation of addition
81if ($action == 'vadd' && $cancel != $langs->trans("Cancel") && $permissiontoadd) {
82 $object->fetch($id);
83 $current_lang = $langs->getDefaultLang();
84
85 // check parameters
86 $forcelangprod = GETPOST('forcelangprod', 'alpha');
87 $libelle = GETPOST('libelle', 'alpha');
88 $desc = GETPOST('desc', 'restricthtml');
89
90 if (empty($forcelangprod)) {
91 $error++;
92 $object->errors[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Translation'));
93 }
94
95 if (!$error) {
96 if (empty($libelle)) {
97 $error++;
98 $object->errors[] = $langs->trans('Language_'.$forcelangprod).' : '.$langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Label'));
99 }
100
101 if (!$error) {
102 // update the object
103 if ($forcelangprod == $current_lang) {
104 $object->label = $libelle;
105 $object->description = dol_htmlcleanlastbr($desc);
106 } else {
107 $object->multilangs[$forcelangprod]["label"] = $libelle;
108 $object->multilangs[$forcelangprod]["description"] = dol_htmlcleanlastbr($desc);
109 }
110
111 // save in base / sauvegarde en base
112 $res = $object->setMultiLangs($user);
113 if ($res < 0) {
114 $error++;
115 }
116 }
117 }
118
119 if ($error) {
120 $action = 'add';
121 setEventMessages($object->error, $object->errors, 'errors');
122 } else {
123 $action = '';
124 }
125}
126
127// validation of the edition
128if ($action == 'vedit' && $cancel != $langs->trans("Cancel") && $permissiontoadd) {
129 $object->fetch($id);
130 $current_lang = $langs->getDefaultLang();
131
132 foreach ($object->multilangs as $key => $value) { // recording of new values in the object
133 $libelle = GETPOST('libelle-'.$key, 'alpha');
134 $desc = GETPOST('desc-'.$key, 'restricthtml');
135
136 if (empty($libelle)) {
137 $error++;
138 $object->errors[] = $langs->trans('Language_'.$key).' : '.$langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Label'));
139 }
140
141 if ($key == $current_lang) {
142 $object->label = $libelle;
143 $object->description = dol_htmlcleanlastbr($desc);
144 } else {
145 $object->multilangs[$key]["label"] = $libelle;
146 $object->multilangs[$key]["description"] = dol_htmlcleanlastbr($desc);
147 }
148 }
149
150 if (!$error) {
151 $res = $object->setMultiLangs($user);
152 if ($res < 0) {
153 $error++;
154 }
155 }
156
157 if ($error) {
158 $action = 'edit';
159 setEventMessages($object->error, $object->errors, 'errors');
160 } else {
161 $action = '';
162 }
163}
164
165
166/*
167 * View
168 */
169
170$form = new Form($db);
171$formadmin = new FormAdmin($db);
172$formother = new FormOther($db);
173
174llxHeader("", "", $langs->trans("Translation"));
175
176$title = Categorie::$MAP_TYPE_TITLE_AREA[$type];
177
178$head = categories_prepare_head($object, $type);
179
180// Calculate $cnt_trans
181$cnt_trans = 0;
182if (!empty($object->multilangs)) {
183 foreach ($object->multilangs as $key => $value) {
184 $cnt_trans++;
185 }
186}
187
188print dol_get_fiche_head($head, 'translation', $langs->trans($title), -1, 'category');
189
190$backtolist = (GETPOST('backtolist') ? GETPOST('backtolist') : DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.urlencode($type));
191$linkback = '<a href="'.dol_sanitizeUrl($backtolist).'">'.$langs->trans("BackToList").'</a>';
192$object->next_prev_filter = 'type = '.((int) $object->type);
193$object->ref = $object->label;
194$morehtmlref = '<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> ';
195$ways = $object->print_all_ways(" &gt;&gt; ", '', 1);
196foreach ($ways as $way) {
197 $morehtmlref .= $way."<br>\n";
198}
199$morehtmlref .= '</div>';
200
201dol_banner_tab($object, 'label', $linkback, ($user->socid ? 0 : 1), 'label', 'label', $morehtmlref, '&type='.$type, 0, '', '', 1);
202
203print '<br>';
204
205print '<div class="fichecenter">';
206print '<div class="underbanner clearboth"></div>';
207
208print '<table class="border centpercent tableforfield">';
209
210// Description
211print '<tr><td class="titlefield notopnoleft">';
212print $langs->trans("Description").'</td><td>';
213print dol_htmlentitiesbr($object->description);
214print '</td></tr>';
215
216// Color
217print '<tr><td class="notopnoleft">';
218print $langs->trans("Color").'</td><td>';
219print $formother->showColor($object->color);
220print '</td></tr>';
221
222print '</table>';
223print '</div>';
224
225print dol_get_fiche_end();
226
227
228
229/*
230 * Action bar
231 */
232
233print "\n<div class=\"tabsAction\">\n";
234
235if ($action == '') {
236 if ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer')) {
237 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=add&token='.newToken().'&id='.$object->id.'&type='.$type.'">'.$langs->trans('Add').'</a>';
238 if ($cnt_trans > 0) {
239 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&token='.newToken().'&id='.$object->id.'&type='.$type.'">'.$langs->trans('Update').'</a>';
240 }
241 }
242}
243
244print "\n</div>\n";
245
246
247
248if ($action == 'edit') {
249 // WYSIWYG Editor
250 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
251
252 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
253 print '<input type="hidden" name="token" value="'.newToken().'">';
254 print '<input type="hidden" name="action" value="vedit">';
255 print '<input type="hidden" name="id" value="'.$object->id.'">';
256 print '<input type="hidden" name="type" value="'.$type.'">';
257
258 if (!empty($object->multilangs)) {
259 foreach ($object->multilangs as $key => $value) {
260 print "<br><b><u>".$langs->trans('Language_'.$key)." :</u></b><br>";
261 print '<table class="border centpercent">';
262
263 // Label
264 $libelle = (GETPOST('libelle-'.$key, 'alpha') ? GETPOST('libelle-'.$key, 'alpha') : ($object->multilangs[$key]['label'] ?? ''));
265 print '<tr><td class="titlefield fieldrequired">'.$langs->trans('Label').'</td><td><input name="libelle-'.$key.'" size="40" value="'.$libelle.'"></td></tr>';
266
267 // Desc
268 $desc = (GETPOST('desc-'.$key) ? GETPOST('desc-'.$key) : ($object->multilangs[$key]['description'] ?? ''));
269 print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
270 $doleditor = new DolEditor("desc-$key", $desc, '', 160, 'dolibarr_notes', '', false, true, isModEnabled('fckeditor') && getDolGlobalInt('FCKEDITOR_ENABLE_SOCIETE'), ROWS_3, '90%');
271 $doleditor->Create();
272 print '</td></tr>';
273
274 print '</tr>';
275 print '</table>';
276 }
277 }
278
279 print '<br>';
280
281 print $form->buttonsSaveCancel();
282
283 print '</form>';
284} elseif ($action != 'add') {
285 if ($cnt_trans) {
286 print '<div class="underbanner clearboth"></div>';
287 }
288
289 if (!empty($object->multilangs)) {
290 foreach ($object->multilangs as $key => $value) {
291 $s = picto_from_langcode((string) $key);
292 print '<table class="border centpercent">';
293 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>';
294 print '<tr><td class="titlefield">'.$langs->trans('Label').'</td><td>'.($object->multilangs[$key]["label"] ?? '').'</td></tr>';
295 print '<tr><td>'.$langs->trans('Description').'</td><td>'.($object->multilangs[$key]["description"] ?? '').'</td></tr>';
296 if (getDolGlobalString('CATEGORY_USE_OTHER_FIELD_IN_TRANSLATION')) {
297 print '<tr><td>'.$langs->trans('Other').' ('.$langs->trans("NotYetAvailable").')</td><td>'.($object->multilangs[$key]["other"] ?? '').'</td></tr>';
298 }
299 print '</table>';
300 }
301 }
302 if (!$cnt_trans && $action != 'add') {
303 print '<div class="opacitymedium">'.$langs->trans('NoTranslation').'</div>';
304 }
305}
306
307
308/*
309 * Form to add a new translation
310 */
311
312if ($action == 'add' && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
313 //WYSIWYG Editor
314 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
315
316 print '<br>';
317 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
318 print '<input type="hidden" name="token" value="'.newToken().'">';
319 print '<input type="hidden" name="action" value="vadd">';
320 print '<input type="hidden" name="id" value="'.$id.'">';
321 print '<input type="hidden" name="type" value="'.$type.'">';
322
323 print '<table class="border centpercent">';
324 print '<tr><td class="titlefield fieldrequired">'.$langs->trans('Translation').'</td><td>';
325 print $formadmin->select_language(GETPOST('forcelangprod', 'alpha'), 'forcelangprod', 0, $object->multilangs);
326 print '</td></tr>';
327 print '<tr><td class="fieldrequired">'.$langs->trans('Label').'</td>';
328 print '<td><input name="libelle" class="minwidth200 maxwidth300" value="'.GETPOST('libelle', 'alpha').'"></td></tr>';
329 print '<tr><td>'.$langs->trans('Description').'</td><td>';
330 $doleditor = new DolEditor('desc', GETPOST('desc', 'restricthtml'), '', 160, 'dolibarr_notes', '', false, true, isModEnabled('fckeditor') && getDolGlobalInt('FCKEDITOR_ENABLE_SOCIETE'), ROWS_3, '90%');
331 $doleditor->Create();
332 print '</td></tr>';
333
334 print '</tr>';
335 print '</table>';
336
337 print $form->buttonsSaveCancel();
338
339 print '</form>';
340
341 print '<br>';
342}
343
344// End of page
345llxFooter();
346$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.