dolibarr  16.0.5
traduction.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005-2018 Regis Houssin <regis.houssin@inodbox.com>
3  * Copyright (C) 2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
4  * Copyright (C) 2010-2012 Destailleur Laurent <eldy@users.sourceforge.net>
5  * Copyright (C) 2014 Henry Florian <florian.henry@open-concept.pro>
6  * Copyright (C) 2023 Benjamin Falière <benjamin.faliere@altairis.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  * or see https://www.gnu.org/
21  */
22 
29 require '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
34 
35 // Load translation files required by the page
36 $langs->loadLangs(array('products', 'languages'));
37 
38 $id = GETPOST('id', 'int');
39 $ref = GETPOST('ref', 'alpha');
40 $action = GETPOST('action', 'aZ09');
41 $cancel = GETPOST('cancel', 'alpha');
42 
43 // Security check
44 $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
45 $fieldtype = (!empty($ref) ? 'ref' : 'rowid');
46 if ($user->socid) {
47  $socid = $user->socid;
48 }
49 
50 if ($id > 0 || !empty($ref)) {
51  $object = new Product($db);
52  $object->fetch($id, $ref);
53 }
54 
55 if ($object->id > 0) {
56  if ($object->type == $object::TYPE_PRODUCT) {
57  restrictedArea($user, 'produit', $object->id, 'product&product', '', '');
58  }
59  if ($object->type == $object::TYPE_SERVICE) {
60  restrictedArea($user, 'service', $object->id, 'product&product', '', '');
61  }
62 } else {
63  restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
64 }
65 
66 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
67 $hookmanager->initHooks(array('producttranslationcard', 'globalcard'));
68 
69 
70 /*
71  * Actions
72  */
73 
74 $parameters = array('id'=>$id, 'ref'=>$ref);
75 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
76 if ($reshook < 0) {
77  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
78 }
79 if (empty($reshook)) {
80  // retour a l'affichage des traduction si annulation
81  if ($cancel == $langs->trans("Cancel")) {
82  $action = '';
83  }
84 
85  if ($action == 'delete' && GETPOST('langtodelete', 'alpha')) {
86  $object = new Product($db);
87  $object->fetch($id);
88  $object->delMultiLangs(GETPOST('langtodelete', 'alpha'), $user);
89  setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
90  $action = '';
91  }
92 
93  // Add translation
94  if ($action == 'vadd' && $cancel != $langs->trans("Cancel") && ($user->rights->produit->creer || $user->rights->service->creer)) {
95  $object = new Product($db);
96  $object->fetch($id);
97  $current_lang = $langs->getDefaultLang();
98 
99  // update de l'objet
100  if (GETPOST("forcelangprod") == $current_lang) {
101  $object->label = GETPOST("libelle");
102  $object->description = dol_htmlcleanlastbr(GETPOST("desc", 'restricthtml'));
103  $object->other = dol_htmlcleanlastbr(GETPOST("other", 'restricthtml'));
104 
105  $object->update($object->id, $user);
106  } else {
107  $object->multilangs[GETPOST("forcelangprod")]["label"] = GETPOST("libelle");
108  $object->multilangs[GETPOST("forcelangprod")]["description"] = dol_htmlcleanlastbr(GETPOST("desc", 'restricthtml'));
109  $object->multilangs[GETPOST("forcelangprod")]["other"] = dol_htmlcleanlastbr(GETPOST("other", 'restricthtml'));
110  }
111 
112  // save in database
113  if (GETPOST("forcelangprod")) {
114  $result = $object->setMultiLangs($user);
115  } else {
116  $object->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Language"));
117  $result = -1;
118  }
119 
120  if ($result > 0) {
121  $action = '';
122  } else {
123  $action = 'add';
124  setEventMessages($object->error, $object->errors, 'errors');
125  }
126  }
127 
128  // Edit translation
129  if ($action == 'vedit' && $cancel != $langs->trans("Cancel") && ($user->rights->produit->creer || $user->rights->service->creer)) {
130  $object = new Product($db);
131  $object->fetch($id);
132  $current_lang = $langs->getDefaultLang();
133 
134  foreach ($object->multilangs as $key => $value) { // enregistrement des nouvelles valeurs dans l'objet
135  if ($key == $current_lang) {
136  $object->label = GETPOST("libelle-" . $key);
137  $object->description = dol_htmlcleanlastbr(GETPOST("desc-" . $key, 'restricthtml'));
138  $object->other = dol_htmlcleanlastbr(GETPOST("other-" . $key, 'restricthtml'));
139 
140  $object->update($object->id, $user);
141  } else {
142  $object->multilangs[$key]["label"] = GETPOST("libelle-" . $key);
143  $object->multilangs[$key]["description"] = dol_htmlcleanlastbr(GETPOST("desc-" . $key, 'restricthtml'));
144  $object->multilangs[$key]["other"] = dol_htmlcleanlastbr(GETPOST("other-" . $key, 'restricthtml'));
145  }
146  }
147 
148  $result = $object->setMultiLangs($user);
149  if ($result > 0) {
150  $action = '';
151  } else {
152  $action = 'edit';
153  setEventMessages($object->error, $object->errors, 'errors');
154  }
155  }
156 
157  // Delete translation
158  if ($action == 'vdelete' && $cancel != $langs->trans("Cancel") && ($user->rights->produit->creer || $user->rights->service->creer)) {
159  $object = new Product($db);
160  $object->fetch($id);
161  $langtodelete = GETPOST('langdel', 'alpha');
162 
163  $result = $object->delMultiLangs($langtodelete, $user);
164  if ($result > 0) {
165  $action = '';
166  } else {
167  $action = 'edit';
168  setEventMessages($object->error, $object->errors, 'errors');
169  }
170  }
171 }
172 
173 $object = new Product($db);
174 $result = $object->fetch($id, $ref);
175 
176 
177 /*
178  * View
179  */
180 
181 $title = $langs->trans('ProductServiceCard');
182 $helpurl = '';
183 $shortlabel = dol_trunc($object->label, 16);
184 if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) {
185  $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('Translation');
186  $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
187 }
188 if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) {
189  $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('Translation');
190  $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
191 }
192 
193 llxHeader('', $title, $helpurl);
194 
195 $form = new Form($db);
196 $formadmin = new FormAdmin($db);
197 
198 $head = product_prepare_head($object);
199 $titre = $langs->trans("CardProduct".$object->type);
200 $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
201 
202 
203 // Calculate $cnt_trans
204 $cnt_trans = 0;
205 if (!empty($object->multilangs)) {
206  foreach ($object->multilangs as $key => $value) {
207  $cnt_trans++;
208  }
209 }
210 
211 
212 print dol_get_fiche_head($head, 'translation', $titre, 0, $picto);
213 
214 $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
215 
216 $shownav = 1;
217 if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
218  $shownav = 0;
219 }
220 
221 dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref', '', '', '', 0, '', '', 1);
222 
223 print dol_get_fiche_end();
224 
225 
226 
227 /*
228  * Action bar
229  */
230 print "\n".'<div class="tabsAction">'."\n";
231 
232 $parameters = array();
233 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
234 if (empty($reshook)) {
235  if ($action == '') {
236  if ($user->rights->produit->creer || $user->rights->service->creer) {
237  print '<a class="butAction" href="' . DOL_URL_ROOT . '/product/traduction.php?action=add&token='.newToken().'&id=' . $object->id . '">' . $langs->trans("Add") . '</a>';
238  if ($cnt_trans > 0) {
239  print '<a class="butAction" href="' . DOL_URL_ROOT . '/product/traduction.php?action=edit&token='.newToken().'&id=' . $object->id . '">' . $langs->trans("Modify") . '</a>';
240  }
241  }
242  }
243 }
244 
245 print "\n".'</div>'."\n";
246 
247 
248 
249 if ($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 
258  if (!empty($object->multilangs)) {
259  $i = 0;
260  foreach ($object->multilangs as $key => $value) {
261  $i++;
262 
263  $s = picto_from_langcode($key);
264  print ($i > 1 ? "<br>" : "").($s ? $s.' ' : '').' <div class="inline-block margintop marginbottomonly"><b>'.$langs->trans('Language_'.$key).'</b></div><div class="inline-block floatright"><a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'&langtodelete='.$key.'">'.img_delete('', 'class="valigntextbottom marginrightonly"').'</a></div>';
265 
266  print '<div class="underbanner clearboth"></div>';
267  print '<table class="border centpercent">';
268  print '<tr><td class="tdtop titlefieldcreate fieldrequired">'.$langs->trans('Label').'</td><td><input name="libelle-'.$key.'" size="40" value="'.dol_escape_htmltag($object->multilangs[$key]["label"]).'"></td></tr>';
269  print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
270  $doleditor = new DolEditor("desc-$key", $object->multilangs[$key]["description"], '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_PRODUCTDESC'), ROWS_3, '90%');
271  $doleditor->Create();
272  print '</td></tr>';
273  if (!empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) {
274  print '<tr><td class="tdtop">'.$langs->trans('Other').' ('.$langs->trans("NotUsed").')</td><td>';
275  $doleditor = new DolEditor("other-$key", $object->multilangs[$key]["other"], '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_PRODUCTDESC'), ROWS_3, '90%');
276  $doleditor->Create();
277  }
278  print '</td></tr>';
279  print '</table>';
280  }
281  }
282 
283  $parameters = array();
284  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
285 
286  print '<br>';
287 
288  print $form->buttonsSaveCancel();
289 
290  print '</form>';
291 } elseif ($action != 'add') {
292  if (!empty($object->multilangs)) {
293  $i = 0;
294  foreach ($object->multilangs as $key => $value) {
295  $i++;
296 
297  $s = picto_from_langcode($key);
298  print ($i > 1 ? "<br>" : "").($s ? $s.' ' : '').' <div class="inline-block marginbottomonly"><b>'.$langs->trans('Language_'.$key).'</b></div><div class="inline-block floatright"><a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'&langtodelete='.$key.'">'.img_delete('', 'class="valigntextbottom marginrightonly"').'</a></div>';
299 
300  print '<div class="fichecenter">';
301  print '<div class="underbanner clearboth"></div>';
302  print '<table class="border centpercent">';
303  print '<tr><td class="titlefieldcreate">'.$langs->trans('Label').'</td><td>'.$object->multilangs[$key]["label"].'</td></tr>';
304  print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>'.$object->multilangs[$key]["description"].'</td></tr>';
305  if (!empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) {
306  print '<tr><td>'.$langs->trans('Other').' ('.$langs->trans("NotUsed").')</td><td>'.$object->multilangs[$key]["other"].'</td></tr>';
307  }
308  print '</table>';
309  print '</div>';
310  }
311  }
312  if (!$cnt_trans && $action != 'add') {
313  print '<div class="opacitymedium">'.$langs->trans('NoTranslation').'</div>';
314  }
315 }
316 
317 
318 
319 /*
320  * Form to add a new translation
321  */
322 
323 if ($action == 'add' && ($user->rights->produit->creer || $user->rights->service->creer)) {
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="'.GETPOST("id", 'int').'">';
332 
333  print dol_get_fiche_head();
334 
335  print '<table class="border centpercent">';
336  print '<tr><td class="tdtop titlefieldcreate fieldrequired">'.$langs->trans('Language').'</td><td>';
337  print $formadmin->select_language(GETPOST('forcelangprod'), 'forcelangprod', 0, $object->multilangs, 1);
338  print '</td></tr>';
339  print '<tr><td class="tdtop fieldrequired">'.$langs->trans('Label').'</td><td><input name="libelle" size="40"></td></tr>';
340  print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
341  $doleditor = new DolEditor('desc', '', '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_PRODUCTDESC'), ROWS_3, '90%');
342  $doleditor->Create();
343  print '</td></tr>';
344  // Other field (not used)
345  if (!empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) {
346  print '<tr><td class="tdtop">'.$langs->trans('Other').' ('.$langs->trans("NotUsed").'</td><td>';
347  $doleditor = new DolEditor('other', '', '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_PRODUCTDESC'), ROWS_3, '90%');
348  $doleditor->Create();
349  print '</td></tr>';
350  }
351  print '</table>';
352 
353  $parameters = array();
354  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
355 
356  print dol_get_fiche_end();
357 
358  print $form->buttonsSaveCancel();
359 
360  print '</form>';
361 
362  print '<br>';
363 }
364 
365 // End of page
366 llxFooter();
367 $db->close();
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
dol_trunc
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
Definition: functions.lib.php:3805
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
product_prepare_head
product_prepare_head($object)
Prepare array with list of tabs.
Definition: product.lib.php:35
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
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
Product
Class to manage products or services.
Definition: product.class.php:46
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
Product\TYPE_SERVICE
const TYPE_SERVICE
Service.
Definition: product.class.php:504
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
Product\TYPE_PRODUCT
const TYPE_PRODUCT
Regular product.
Definition: product.class.php:500
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