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