dolibarr  19.0.0-dev
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
29 require '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
34 require_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 
44 if ($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);
54 if ($result <= 0) {
55  dol_print_error($db, $object->error); exit;
56 }
57 
58 $type = $object->type;
59 if (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
71 if ($cancel == $langs->trans("Cancel")) {
72  $action = '';
73 }
74 
75 
76 // validation of addition
77 if ($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
126 if ($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);
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 
174 llxHeader("", "", $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;
182 if (!empty($object->multilangs)) {
183  foreach ($object->multilangs as $key => $value) {
184  $cnt_trans++;
185  }
186 }
187 
188 print 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 = '.$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);
196 foreach ($ways as $way) {
197  $morehtmlref .= $way."<br>\n";
198 }
199 $morehtmlref .= '</div>';
200 
201 dol_banner_tab($object, 'label', $linkback, ($user->socid ? 0 : 1), 'label', 'label', $morehtmlref, '&type='.$type, 0, '', '', 1);
202 
203 print '<br>';
204 
205 print '<div class="fichecenter">';
206 print '<div class="underbanner clearboth"></div>';
207 
208 print '<table class="border centpercent tableforfield">';
209 
210 // Description
211 print '<tr><td class="titlefield notopnoleft">';
212 print $langs->trans("Description").'</td><td>';
213 print dol_htmlentitiesbr($object->description);
214 print '</td></tr>';
215 
216 // Color
217 print '<tr><td class="notopnoleft">';
218 print $langs->trans("Color").'</td><td>';
219 print $formother->showColor($object->color);
220 print '</td></tr>';
221 
222 print '</table>';
223 print '</div>';
224 
225 print dol_get_fiche_end();
226 
227 
228 
229 /*
230  * Action bar
231  */
232 
233 print "\n<div class=\"tabsAction\">\n";
234 
235 if ($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 
244 print "\n</div>\n";
245 
246 
247 
248 if ($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 
312 if ($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
345 llxFooter();
346 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:609
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:5107
picto_from_langcode
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
Definition: functions.lib.php:9305
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
FormOther
Classe permettant la generation de composants html autre Only common components are here.
Definition: html.formother.class.php:39
Categorie
Class to manage categories.
Definition: categorie.class.php:47
FormAdmin
Class to generate html code for admin pages.
Definition: html.formadmin.class.php:30
dol_banner_tab
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.
Definition: functions.lib.php:2205
llxHeader
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
img_delete
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
Definition: functions.lib.php:4692
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
Definition: functions.lib.php:8673
dol_htmlcleanlastbr
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
Definition: functions.lib.php:7518
restrictedArea
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.
Definition: security.lib.php:353
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:11654
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2177
dol_get_fiche_head
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.
Definition: functions.lib.php:1979
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:53
dol_htmlentitiesbr
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...
Definition: functions.lib.php:7469
categories_prepare_head
categories_prepare_head(Categorie $object, $type)
Prepare array with list of tabs.
Definition: categories.lib.php:32
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:156
DolEditor
Class to manage a WYSIWYG editor.
Definition: doleditor.class.php:30