dolibarr 18.0.6
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); 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
64/*
65 * Actions
66 */
67
68$error = 0;
69
70// return to translation view if cancelled
71if ($cancel == $langs->trans("Cancel")) {
72 $action = '';
73}
74
75
76// validation of addition
77if ($action == 'vadd' &&
78$cancel != $langs->trans("Cancel") &&
79($user->rights->categorie->creer)) {
80 $object->fetch($id);
81 $current_lang = $langs->getDefaultLang();
82
83 // check parameters
84 $forcelangprod = GETPOST('forcelangprod', 'alpha');
85 $libelle = GETPOST('libelle', 'alpha');
86 $desc = GETPOST('desc', 'restricthtml');
87
88 if (empty($forcelangprod)) {
89 $error++;
90 $object->errors[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Translation'));
91 }
92
93 if (!$error) {
94 if (empty($libelle)) {
95 $error++;
96 $object->errors[] = $langs->trans('Language_'.$forcelangprod).' : '.$langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Label'));
97 }
98
99 if (!$error) {
100 // update the object
101 if ($forcelangprod == $current_lang) {
102 $object->label = $libelle;
103 $object->description = dol_htmlcleanlastbr($desc);
104 } else {
105 $object->multilangs[$forcelangprod]["label"] = $libelle;
106 $object->multilangs[$forcelangprod]["description"] = dol_htmlcleanlastbr($desc);
107 }
108
109 // save in base / sauvegarde en base
110 $res = $object->setMultiLangs($user);
111 if ($res < 0) {
112 $error++;
113 }
114 }
115 }
116
117 if ($error) {
118 $action = 'add';
119 setEventMessages($object->error, $object->errors, 'errors');
120 } else {
121 $action = '';
122 }
123}
124
125// validation of the edition
126if ($action == 'vedit' &&
127$cancel != $langs->trans("Cancel") &&
128($user->rights->categorie->creer)) {
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, 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($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 (!empty($conf->global->CATEGORY_USE_OTHER_FIELD_IN_TRANSLATION)) {
297 print '<tr><td>'.$langs->trans('Other').' ('.$langs->trans("NotUsed").')</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, 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();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:56
llxFooter()
Empty footer.
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.
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 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...
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.