dolibarr  13.0.2
traduction.php
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 require '../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
34 
35 // Load translation files required by the page
36 $langs->loadLangs(array('categories', 'languages'));
37 
38 $id = GETPOST('id', 'int');
39 $label = GETPOST('label', 'alpha');
40 $action = GETPOST('action', 'aZ09');
41 $cancel = GETPOST('cancel', 'alpha');
42 $type = GETPOST('type', 'aZ09');
43 
44 if ($id == '' && $label == '')
45 {
46  dol_print_error('', 'Missing parameter id');
47  exit();
48 }
49 
50 // Security check
51 $result = restrictedArea($user, 'categorie', $id, '&category');
52 
53 $object = new Categorie($db);
54 $result = $object->fetch($id, $label, $type);
55 if ($result <= 0) {
56  dol_print_error($db, $object->error); exit;
57 }
58 $object->fetch_optionals();
59 if ($result <= 0) {
60  dol_print_error($db, $object->error); exit;
61 }
62 
63 if (is_numeric($type)) $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
64 
65 /*
66  * Actions
67  */
68 $error = 0;
69 
70 // retour a l'affichage des traduction si annulation
71 if ($cancel == $langs->trans("Cancel"))
72 {
73  $action = '';
74 }
75 
76 
77 // Validation de l'ajout
78 if ($action == 'vadd' &&
79 $cancel != $langs->trans("Cancel") &&
80 ($user->rights->categorie->creer))
81 {
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 de l'objet
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  // sauvegarde en base
112  $res = $object->setMultiLangs($user);
113  if ($res < 0) $error++;
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 de l'edition
126 if ($action == 'vedit' &&
127 $cancel != $langs->trans("Cancel") &&
128 ($user->rights->categorie->creer))
129 {
130  $object->fetch($id);
131  $current_lang = $langs->getDefaultLang();
132 
133  foreach ($object->multilangs as $key => $value) // enregistrement des nouvelles valeurs dans l'objet
134  {
135  $libelle = GETPOST('libelle-'.$key, 'alpha');
136  $desc = GETPOST('desc-'.$key);
137 
138  if (empty($libelle)) {
139  $error++;
140  $object->errors[] = $langs->trans('Language_'.$key).' : '.$langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Label'));
141  }
142 
143  if ($key == $current_lang) {
144  $object->label = $libelle;
145  $object->description = dol_htmlcleanlastbr($desc);
146  } else {
147  $object->multilangs[$key]["label"] = $libelle;
148  $object->multilangs[$key]["description"] = dol_htmlcleanlastbr($desc);
149  }
150  }
151 
152  if (!$error) {
153  $res = $object->setMultiLangs($user);
154  if ($res < 0) $error++;
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 {
184  foreach ($object->multilangs as $key => $value)
185  {
186  $cnt_trans++;
187  }
188 }
189 
190 print dol_get_fiche_head($head, 'translation', $langs->trans($title), -1, 'category');
191 
192 $linkback = '<a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("BackToList").'</a>';
193 $object->next_prev_filter = ' type = '.$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);
197 foreach ($ways as $way) {
198  $morehtmlref .= $way."<br>\n";
199 }
200 $morehtmlref .= '</div>';
201 
202 dol_banner_tab($object, 'label', $linkback, ($user->socid ? 0 : 1), 'label', 'label', $morehtmlref, '&type='.$type, 0, '', '', 1);
203 
204 print '<br>';
205 
206 print '<div class="fichecenter">';
207 print '<div class="underbanner clearboth"></div>';
208 
209 print '<table class="border centpercent tableforfield">';
210 
211 // Description
212 print '<tr><td class="titlefield notopnoleft">';
213 print $langs->trans("Description").'</td><td>';
214 print dol_htmlentitiesbr($object->description);
215 print '</td></tr>';
216 
217 // Color
218 print '<tr><td class="notopnoleft">';
219 print $langs->trans("Color").'</td><td>';
220 print $formother->showColor($object->color);
221 print '</td></tr>';
222 
223 print '</table>';
224 print '</div>';
225 
227 
228 
229 
230 
231 /* ************************************************************************** */
232 /* */
233 /* Barre d'action */
234 /* */
235 /* ************************************************************************** */
236 
237 print "\n<div class=\"tabsAction\">\n";
238 
239 if ($action == '')
240 {
241  if ($user->rights->produit->creer || $user->rights->service->creer)
242  {
243  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=add&id='.$object->id.'&type='.$type.'">'.$langs->trans('Add').'</a>';
244  if ($cnt_trans > 0) print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&id='.$object->id.'&type='.$type.'">'.$langs->trans('Update').'</a>';
245  }
246 }
247 
248 print "\n</div>\n";
249 
250 
251 
252 if ($action == 'edit')
253 {
254  //WYSIWYG Editor
255  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
256 
257  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
258  print '<input type="hidden" name="token" value="'.newToken().'">';
259  print '<input type="hidden" name="action" value="vedit">';
260  print '<input type="hidden" name="id" value="'.$object->id.'">';
261  print '<input type="hidden" name="type" value="'.$type.'">';
262 
263  if (!empty($object->multilangs))
264  {
265  foreach ($object->multilangs as $key => $value)
266  {
267  print "<br><b><u>".$langs->trans('Language_'.$key)." :</u></b><br>";
268  print '<table class="border centpercent">';
269 
270  // Label
271  $libelle = (GETPOST('libelle-'.$key, 'alpha') ? GETPOST('libelle-'.$key, 'alpha') : $object->multilangs[$key]['label']);
272  print '<tr><td class="titlefield fieldrequired">'.$langs->trans('Label').'</td><td><input name="libelle-'.$key.'" size="40" value="'.$libelle.'"></td></tr>';
273  // Desc
274  $desc = (GETPOST('desc-'.$key) ? GETPOST('desc-'.$key) : $object->multilangs[$key]['description']);
275  print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
276  $doleditor = new DolEditor("desc-$key", $desc, '', 160, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, ROWS_3, '90%');
277  $doleditor->Create();
278  print '</td></tr>';
279 
280  print '</tr>';
281  print '</table>';
282  }
283  }
284 
285  print '<br>';
286 
287  print '<div class="center">';
288  print '<input type="submit" class="button button-save" value="'.$langs->trans("Save").'">';
289  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
290  print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
291  print '</div>';
292 
293  print '</form>';
294 } elseif ($action != 'add')
295 {
296  if ($cnt_trans) print '<div class="underbanner clearboth"></div>';
297 
298  if (!empty($object->multilangs))
299  {
300  foreach ($object->multilangs as $key => $value)
301  {
302  $s = picto_from_langcode($key);
303  print '<table class="border centpercent">';
304  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>';
305  print '<tr><td class="titlefield">'.$langs->trans('Label').'</td><td>'.$object->multilangs[$key]["label"].'</td></tr>';
306  print '<tr><td>'.$langs->trans('Description').'</td><td>'.$object->multilangs[$key]["description"].'</td></tr>';
307  if (!empty($conf->global->CATEGORY_USE_OTHER_FIELD_IN_TRANSLATION))
308  {
309  print '<tr><td>'.$langs->trans('Other').' ('.$langs->trans("NotUsed").')</td><td>'.$object->multilangs[$key]["other"].'</td></tr>';
310  }
311  print '</table>';
312  }
313  }
314  if (!$cnt_trans && $action != 'add') print '<div class="opacitymedium">'.$langs->trans('NoTranslation').'</div>';
315 }
316 
317 
318 /*
319  * Form to add a new translation
320  */
321 
322 if ($action == 'add' && ($user->rights->produit->creer || $user->rights->service->creer))
323 {
324  //WYSIWYG Editor
325  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
326 
327  print '<br>';
328  print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
329  print '<input type="hidden" name="token" value="'.newToken().'">';
330  print '<input type="hidden" name="action" value="vadd">';
331  print '<input type="hidden" name="id" value="'.$id.'">';
332  print '<input type="hidden" name="type" value="'.$type.'">';
333 
334  print '<table class="border centpercent">';
335  print '<tr><td class="titlefield fieldrequired">'.$langs->trans('Translation').'</td><td>';
336  print $formadmin->select_language(GETPOST('forcelangprod', 'alpha'), 'forcelangprod', 0, $object->multilangs);
337  print '</td></tr>';
338  print '<tr><td class="fieldrequired">'.$langs->trans('Label').'</td>';
339  print '<td><input name="libelle" class="minwidth200 maxwidth300" value="'.GETPOST('libelle', 'alpha').'"></td></tr>';
340  print '<tr><td>'.$langs->trans('Description').'</td><td>';
341  $doleditor = new DolEditor('desc', GETPOST('desc', 'restricthtml'), '', 160, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, ROWS_3, '90%');
342  $doleditor->Create();
343  print '</td></tr>';
344 
345  print '</tr>';
346  print '</table>';
347 
348  print '<div class="center">';
349  print '<input type="submit" class="button button-save" value="'.$langs->trans("Save").'">';
350  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
351  print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
352  print '</div>';
353 
354  print '</form>';
355 
356  print '<br>';
357 }
358 
359 // End of page
360 llxFooter();
361 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
categories_prepare_head(Categorie $object, $type)
Prepare array with list of tabs.
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...
Class to generate html code for admin pages.
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
Class to manage categories.
Classe permettant la generation de composants html autre Only common components are here...
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage a WYSIWYG editor.
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.
llxFooter()
Empty footer.
Definition: wrapper.php:59
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.
picto_from_langcode($codelang, $moreatt= '')
Return img flag of country for a language code or country code.