dolibarr  16.0.5
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 
43 if ($id == '' && $label == '') {
44  dol_print_error('', 'Missing parameter id');
45  exit();
46 }
47 
48 // Security check
49 $result = restrictedArea($user, 'categorie', $id, '&category');
50 
51 $object = new Categorie($db);
52 $result = $object->fetch($id, $label);
53 if ($result <= 0) {
54  dol_print_error($db, $object->error); exit;
55 }
56 
57 $type = $object->type;
58 if (is_numeric($type)) {
59  $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
60 }
61 
62 /*
63  * Actions
64  */
65 $error = 0;
66 
67 // retour a l'affichage des traduction si annulation
68 if ($cancel == $langs->trans("Cancel")) {
69  $action = '';
70 }
71 
72 
73 // Validation de l'ajout
74 if ($action == 'vadd' &&
75 $cancel != $langs->trans("Cancel") &&
76 ($user->rights->categorie->creer)) {
77  $object->fetch($id);
78  $current_lang = $langs->getDefaultLang();
79 
80  // check parameters
81  $forcelangprod = GETPOST('forcelangprod', 'alpha');
82  $libelle = GETPOST('libelle', 'alpha');
83  $desc = GETPOST('desc', 'restricthtml');
84 
85  if (empty($forcelangprod)) {
86  $error++;
87  $object->errors[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Translation'));
88  }
89 
90  if (!$error) {
91  if (empty($libelle)) {
92  $error++;
93  $object->errors[] = $langs->trans('Language_'.$forcelangprod).' : '.$langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Label'));
94  }
95 
96  if (!$error) {
97  // update de l'objet
98  if ($forcelangprod == $current_lang) {
99  $object->label = $libelle;
100  $object->description = dol_htmlcleanlastbr($desc);
101  } else {
102  $object->multilangs[$forcelangprod]["label"] = $libelle;
103  $object->multilangs[$forcelangprod]["description"] = dol_htmlcleanlastbr($desc);
104  }
105 
106  // sauvegarde en base
107  $res = $object->setMultiLangs($user);
108  if ($res < 0) {
109  $error++;
110  }
111  }
112  }
113 
114  if ($error) {
115  $action = 'add';
116  setEventMessages($object->error, $object->errors, 'errors');
117  } else {
118  $action = '';
119  }
120 }
121 
122 // Validation de l'edition
123 if ($action == 'vedit' &&
124 $cancel != $langs->trans("Cancel") &&
125 ($user->rights->categorie->creer)) {
126  $object->fetch($id);
127  $current_lang = $langs->getDefaultLang();
128 
129  foreach ($object->multilangs as $key => $value) { // enregistrement des nouvelles valeurs dans l'objet
130  $libelle = GETPOST('libelle-'.$key, 'alpha');
131  $desc = GETPOST('desc-'.$key);
132 
133  if (empty($libelle)) {
134  $error++;
135  $object->errors[] = $langs->trans('Language_'.$key).' : '.$langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Label'));
136  }
137 
138  if ($key == $current_lang) {
139  $object->label = $libelle;
140  $object->description = dol_htmlcleanlastbr($desc);
141  } else {
142  $object->multilangs[$key]["label"] = $libelle;
143  $object->multilangs[$key]["description"] = dol_htmlcleanlastbr($desc);
144  }
145  }
146 
147  if (!$error) {
148  $res = $object->setMultiLangs($user);
149  if ($res < 0) {
150  $error++;
151  }
152  }
153 
154  if ($error) {
155  $action = 'edit';
156  setEventMessages($object->error, $object->errors, 'errors');
157  } else {
158  $action = '';
159  }
160 }
161 
162 
163 /*
164  * View
165  */
166 
167 $form = new Form($db);
168 $formadmin = new FormAdmin($db);
169 $formother = new FormOther($db);
170 
171 llxHeader("", "", $langs->trans("Translation"));
172 
173 $title = Categorie::$MAP_TYPE_TITLE_AREA[$type];
174 
175 $head = categories_prepare_head($object, $type);
176 
177 // Calculate $cnt_trans
178 $cnt_trans = 0;
179 if (!empty($object->multilangs)) {
180  foreach ($object->multilangs as $key => $value) {
181  $cnt_trans++;
182  }
183 }
184 
185 print dol_get_fiche_head($head, 'translation', $langs->trans($title), -1, 'category');
186 
187 $backtolist = (GETPOST('backtolist') ? GETPOST('backtolist') : DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.urlencode($type));
188 $linkback = '<a href="'.dol_sanitizeUrl($backtolist).'">'.$langs->trans("BackToList").'</a>';
189 $object->next_prev_filter = ' type = '.$object->type;
190 $object->ref = $object->label;
191 $morehtmlref = '<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> ';
192 $ways = $object->print_all_ways(" &gt;&gt; ", '', 1);
193 foreach ($ways as $way) {
194  $morehtmlref .= $way."<br>\n";
195 }
196 $morehtmlref .= '</div>';
197 
198 dol_banner_tab($object, 'label', $linkback, ($user->socid ? 0 : 1), 'label', 'label', $morehtmlref, '&type='.$type, 0, '', '', 1);
199 
200 print '<br>';
201 
202 print '<div class="fichecenter">';
203 print '<div class="underbanner clearboth"></div>';
204 
205 print '<table class="border centpercent tableforfield">';
206 
207 // Description
208 print '<tr><td class="titlefield notopnoleft">';
209 print $langs->trans("Description").'</td><td>';
210 print dol_htmlentitiesbr($object->description);
211 print '</td></tr>';
212 
213 // Color
214 print '<tr><td class="notopnoleft">';
215 print $langs->trans("Color").'</td><td>';
216 print $formother->showColor($object->color);
217 print '</td></tr>';
218 
219 print '</table>';
220 print '</div>';
221 
222 print dol_get_fiche_end();
223 
224 
225 
226 
227 /*
228  * Action bar
229  */
230 print "\n<div class=\"tabsAction\">\n";
231 
232 if ($action == '') {
233  if ($user->rights->produit->creer || $user->rights->service->creer) {
234  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=add&token='.newToken().'&id='.$object->id.'&type='.$type.'">'.$langs->trans('Add').'</a>';
235  if ($cnt_trans > 0) {
236  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&token='.newToken().'&id='.$object->id.'&type='.$type.'">'.$langs->trans('Update').'</a>';
237  }
238  }
239 }
240 
241 print "\n</div>\n";
242 
243 
244 
245 if ($action == 'edit') {
246  //WYSIWYG Editor
247  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
248 
249  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
250  print '<input type="hidden" name="token" value="'.newToken().'">';
251  print '<input type="hidden" name="action" value="vedit">';
252  print '<input type="hidden" name="id" value="'.$object->id.'">';
253  print '<input type="hidden" name="type" value="'.$type.'">';
254 
255  if (!empty($object->multilangs)) {
256  foreach ($object->multilangs as $key => $value) {
257  print "<br><b><u>".$langs->trans('Language_'.$key)." :</u></b><br>";
258  print '<table class="border centpercent">';
259 
260  // Label
261  $libelle = (GETPOST('libelle-'.$key, 'alpha') ? GETPOST('libelle-'.$key, 'alpha') : $object->multilangs[$key]['label']);
262  print '<tr><td class="titlefield fieldrequired">'.$langs->trans('Label').'</td><td><input name="libelle-'.$key.'" size="40" value="'.$libelle.'"></td></tr>';
263  // Desc
264  $desc = (GETPOST('desc-'.$key) ? GETPOST('desc-'.$key) : $object->multilangs[$key]['description']);
265  print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
266  $doleditor = new DolEditor("desc-$key", $desc, '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_PRODUCTDESC'), ROWS_3, '90%');
267  $doleditor->Create();
268  print '</td></tr>';
269 
270  print '</tr>';
271  print '</table>';
272  }
273  }
274 
275  print '<br>';
276 
277  print $form->buttonsSaveCancel();
278 
279  print '</form>';
280 } elseif ($action != 'add') {
281  if ($cnt_trans) {
282  print '<div class="underbanner clearboth"></div>';
283  }
284 
285  if (!empty($object->multilangs)) {
286  foreach ($object->multilangs as $key => $value) {
287  $s = picto_from_langcode($key);
288  print '<table class="border centpercent">';
289  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>';
290  print '<tr><td class="titlefield">'.$langs->trans('Label').'</td><td>'.$object->multilangs[$key]["label"].'</td></tr>';
291  print '<tr><td>'.$langs->trans('Description').'</td><td>'.$object->multilangs[$key]["description"].'</td></tr>';
292  if (!empty($conf->global->CATEGORY_USE_OTHER_FIELD_IN_TRANSLATION)) {
293  print '<tr><td>'.$langs->trans('Other').' ('.$langs->trans("NotUsed").')</td><td>'.$object->multilangs[$key]["other"].'</td></tr>';
294  }
295  print '</table>';
296  }
297  }
298  if (!$cnt_trans && $action != 'add') {
299  print '<div class="opacitymedium">'.$langs->trans('NoTranslation').'</div>';
300  }
301 }
302 
303 
304 /*
305  * Form to add a new translation
306  */
307 
308 if ($action == 'add' && ($user->rights->produit->creer || $user->rights->service->creer)) {
309  //WYSIWYG Editor
310  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
311 
312  print '<br>';
313  print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
314  print '<input type="hidden" name="token" value="'.newToken().'">';
315  print '<input type="hidden" name="action" value="vadd">';
316  print '<input type="hidden" name="id" value="'.$id.'">';
317  print '<input type="hidden" name="type" value="'.$type.'">';
318 
319  print '<table class="border centpercent">';
320  print '<tr><td class="titlefield fieldrequired">'.$langs->trans('Translation').'</td><td>';
321  print $formadmin->select_language(GETPOST('forcelangprod', 'alpha'), 'forcelangprod', 0, $object->multilangs);
322  print '</td></tr>';
323  print '<tr><td class="fieldrequired">'.$langs->trans('Label').'</td>';
324  print '<td><input name="libelle" class="minwidth200 maxwidth300" value="'.GETPOST('libelle', 'alpha').'"></td></tr>';
325  print '<tr><td>'.$langs->trans('Description').'</td><td>';
326  $doleditor = new DolEditor('desc', GETPOST('desc', 'restricthtml'), '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_PRODUCTDESC'), ROWS_3, '90%');
327  $doleditor->Create();
328  print '</td></tr>';
329 
330  print '</tr>';
331  print '</table>';
332 
333  print $form->buttonsSaveCancel();
334 
335  print '</form>';
336 
337  print '<br>';
338 }
339 
340 // End of page
341 llxFooter();
342 $db->close();
restrictedArea
restrictedArea($user, $features, $objectid=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:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
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:484
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:4844
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:8742
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
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:2046
img_delete
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
Definition: functions.lib.php:4429
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_htmlcleanlastbr
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
Definition: functions.lib.php:7036
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
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:6991
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
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:93
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
DolEditor
Class to manage a WYSIWYG editor.
Definition: doleditor.class.php:30