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