dolibarr 19.0.4
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// Load Dolibarr environment
30require '../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
35
36// Load translation files required by the page
37$langs->loadLangs(array('products', 'languages'));
38
39$id = GETPOST('id', 'int');
40$ref = GETPOST('ref', 'alpha');
41$action = GETPOST('action', 'aZ09');
42$cancel = GETPOST('cancel', 'alpha');
43
44// Security check
45$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
46$fieldtype = (!empty($ref) ? 'ref' : 'rowid');
47if ($user->socid) {
48 $socid = $user->socid;
49}
50
51if ($id > 0 || !empty($ref)) {
52 $object = new Product($db);
53 $object->fetch($id, $ref);
54}
55
56if ($object->id > 0) {
57 if ($object->type == $object::TYPE_PRODUCT) {
58 restrictedArea($user, 'produit', $object->id, 'product&product', '', '');
59 }
60 if ($object->type == $object::TYPE_SERVICE) {
61 restrictedArea($user, 'service', $object->id, 'product&product', '', '');
62 }
63} else {
64 restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
65}
66
67// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
68$hookmanager->initHooks(array('producttranslationcard', 'globalcard'));
69
70
71/*
72 * Actions
73 */
74
75$parameters = array('id'=>$id, 'ref'=>$ref);
76$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
77if ($reshook < 0) {
78 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
79}
80if (empty($reshook)) {
81 // retour a l'affichage des traduction si annulation
82 if ($cancel == $langs->trans("Cancel")) {
83 $action = '';
84 }
85
86 if ($action == 'delete' && GETPOST('langtodelete', 'alpha')) {
87 $object = new Product($db);
88 $object->fetch($id);
89 $object->delMultiLangs(GETPOST('langtodelete', 'alpha'), $user);
90 setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
91 $action = '';
92 }
93
94 // Add translation
95 if ($action == 'vadd' && $cancel != $langs->trans("Cancel") && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
96 $object = new Product($db);
97 $object->fetch($id);
98 $current_lang = $langs->getDefaultLang();
99
100 // update de l'objet
101 if (GETPOST("forcelangprod") == $current_lang) {
102 $object->label = GETPOST("libelle");
103 $object->description = dol_htmlcleanlastbr(GETPOST("desc", 'restricthtml'));
104 $object->other = dol_htmlcleanlastbr(GETPOST("other", 'restricthtml'));
105
106 $object->update($object->id, $user);
107 } else {
108 $object->multilangs[GETPOST("forcelangprod")]["label"] = GETPOST("libelle");
109 $object->multilangs[GETPOST("forcelangprod")]["description"] = dol_htmlcleanlastbr(GETPOST("desc", 'restricthtml'));
110 $object->multilangs[GETPOST("forcelangprod")]["other"] = dol_htmlcleanlastbr(GETPOST("other", 'restricthtml'));
111 }
112
113 // save in database
114 if (GETPOST("forcelangprod")) {
115 $result = $object->setMultiLangs($user);
116 } else {
117 $object->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Language"));
118 $result = -1;
119 }
120
121 if ($result > 0) {
122 $action = '';
123 } else {
124 $action = 'add';
125 setEventMessages($object->error, $object->errors, 'errors');
126 }
127 }
128
129 // Edit translation
130 if ($action == 'vedit' && $cancel != $langs->trans("Cancel") && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
131 $object = new Product($db);
132 $object->fetch($id);
133 $current_lang = $langs->getDefaultLang();
134
135 foreach ($object->multilangs as $key => $value) { // enregistrement des nouvelles valeurs dans l'objet
136 if ($key == $current_lang) {
137 $object->label = GETPOST("libelle-" . $key);
138 $object->description = dol_htmlcleanlastbr(GETPOST("desc-" . $key, 'restricthtml'));
139 $object->other = dol_htmlcleanlastbr(GETPOST("other-" . $key, 'restricthtml'));
140
141 $object->update($object->id, $user);
142 } else {
143 $object->multilangs[$key]["label"] = GETPOST("libelle-" . $key);
144 $object->multilangs[$key]["description"] = dol_htmlcleanlastbr(GETPOST("desc-" . $key, 'restricthtml'));
145 $object->multilangs[$key]["other"] = dol_htmlcleanlastbr(GETPOST("other-" . $key, 'restricthtml'));
146 }
147 }
148
149 $result = $object->setMultiLangs($user);
150 if ($result > 0) {
151 $action = '';
152 } else {
153 $action = 'edit';
154 setEventMessages($object->error, $object->errors, 'errors');
155 }
156 }
157
158 // Delete translation
159 if ($action == 'vdelete' && $cancel != $langs->trans("Cancel") && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
160 $object = new Product($db);
161 $object->fetch($id);
162 $langtodelete = GETPOST('langdel', 'alpha');
163
164 $result = $object->delMultiLangs($langtodelete, $user);
165 if ($result > 0) {
166 $action = '';
167 } else {
168 $action = 'edit';
169 setEventMessages($object->error, $object->errors, 'errors');
170 }
171 }
172}
173
174$object = new Product($db);
175$result = $object->fetch($id, $ref);
176
177
178/*
179 * View
180 */
181
182$title = $langs->trans('ProductServiceCard');
183$helpurl = '';
184$shortlabel = dol_trunc($object->label, 16);
185if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) {
186 $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('Translation');
187 $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
188}
189if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) {
190 $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('Translation');
191 $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
192}
193
194llxHeader('', $title, $helpurl);
195
196$form = new Form($db);
197$formadmin = new FormAdmin($db);
198
199$head = product_prepare_head($object);
200$titre = $langs->trans("CardProduct".$object->type);
201$picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
202
203
204// Calculate $cnt_trans
205$cnt_trans = 0;
206if (!empty($object->multilangs)) {
207 foreach ($object->multilangs as $key => $value) {
208 $cnt_trans++;
209 }
210}
211
212
213print dol_get_fiche_head($head, 'translation', $titre, 0, $picto);
214
215$linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1&type='.$object->type.'">'.$langs->trans("BackToList").'</a>';
216
217$shownav = 1;
218if ($user->socid && !in_array('product', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) {
219 $shownav = 0;
220}
221
222dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref', '', '', '', 0, '', '', 1);
223
224print dol_get_fiche_end();
225
226
227
228/*
229 * Action bar
230 */
231print "\n".'<div class="tabsAction">'."\n";
232
233$parameters = array();
234$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
235if (empty($reshook)) {
236 if ($action == '') {
237 if ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer')) {
238 print '<a class="butAction" href="' . DOL_URL_ROOT . '/product/traduction.php?action=add&token='.newToken().'&id=' . $object->id . '">' . $langs->trans("Add") . '</a>';
239 if ($cnt_trans > 0) {
240 print '<a class="butAction" href="' . DOL_URL_ROOT . '/product/traduction.php?action=edit&token='.newToken().'&id=' . $object->id . '">' . $langs->trans("Modify") . '</a>';
241 }
242 }
243 }
244}
245
246print "\n".'</div>'."\n";
247
248
249
250if ($action == 'edit') {
251 //WYSIWYG Editor
252 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
253
254 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
255 print '<input type="hidden" name="token" value="'.newToken().'">';
256 print '<input type="hidden" name="action" value="vedit">';
257 print '<input type="hidden" name="id" value="'.$object->id.'">';
258
259 if (!empty($object->multilangs)) {
260 $i = 0;
261 foreach ($object->multilangs as $key => $value) {
262 $i++;
263
264 $s = picto_from_langcode($key);
265 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>';
266
267 print '<div class="underbanner clearboth"></div>';
268 print '<table class="border centpercent">';
269 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>';
270 print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
271 $doleditor = new DolEditor("desc-$key", $object->multilangs[$key]["description"], '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_DETAILS'), ROWS_3, '90%');
272 $doleditor->Create();
273 print '</td></tr>';
274 if (getDolGlobalString('PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION')) {
275 print '<tr><td class="tdtop">'.$langs->trans('Other').' ('.$langs->trans("NotUsed").')</td><td>';
276 $doleditor = new DolEditor("other-$key", $object->multilangs[$key]["other"], '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_DETAILS'), ROWS_3, '90%');
277 $doleditor->Create();
278 }
279 print '</td></tr>';
280 print '</table>';
281 }
282 }
283
284 $parameters = array();
285 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
286
287 print '<br>';
288
289 print $form->buttonsSaveCancel();
290
291 print '</form>';
292} elseif ($action != 'add') {
293 if (!empty($object->multilangs)) {
294 $i = 0;
295 foreach ($object->multilangs as $key => $value) {
296 $i++;
297
298 $s = picto_from_langcode($key);
299 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>';
300
301 print '<div class="fichecenter">';
302 print '<div class="underbanner clearboth"></div>';
303 print '<table class="border centpercent">';
304 print '<tr><td class="titlefieldcreate">'.$langs->trans('Label').'</td><td>'.$object->multilangs[$key]["label"].'</td></tr>';
305 print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>'.$object->multilangs[$key]["description"].'</td></tr>';
306 if (getDolGlobalString('PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION')) {
307 print '<tr><td>'.$langs->trans('Other').' ('.$langs->trans("NotUsed").')</td><td>'.$object->multilangs[$key]["other"].'</td></tr>';
308 }
309 print '</table>';
310 print '</div>';
311 }
312 }
313 if (!$cnt_trans && $action != 'add') {
314 print '<div class="opacitymedium">'.$langs->trans('NoTranslation').'</div>';
315 }
316}
317
318
319
320/*
321 * Form to add a new translation
322 */
323
324if ($action == 'add' && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
325 //WYSIWYG Editor
326 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
327
328 print '<br>';
329 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
330 print '<input type="hidden" name="token" value="'.newToken().'">';
331 print '<input type="hidden" name="action" value="vadd">';
332 print '<input type="hidden" name="id" value="'.GETPOST("id", 'int').'">';
333
334 print dol_get_fiche_head();
335
336 print '<table class="border centpercent">';
337 print '<tr><td class="tdtop titlefieldcreate fieldrequired">'.$langs->trans('Language').'</td><td>';
338 print $formadmin->select_language(GETPOST('forcelangprod'), 'forcelangprod', 0, $object->multilangs, 1);
339 print '</td></tr>';
340 print '<tr><td class="tdtop fieldrequired">'.$langs->trans('Label').'</td><td><input name="libelle" size="40"></td></tr>';
341 print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
342 $doleditor = new DolEditor('desc', '', '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_DETAILS'), ROWS_3, '90%');
343 $doleditor->Create();
344 print '</td></tr>';
345 // Other field (not used)
346 if (getDolGlobalString('PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION')) {
347 print '<tr><td class="tdtop">'.$langs->trans('Other').' ('.$langs->trans("NotUsed").'</td><td>';
348 $doleditor = new DolEditor('other', '', '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_DETAILS'), ROWS_3, '90%');
349 $doleditor->Create();
350 print '</td></tr>';
351 }
352 print '</table>';
353
354 $parameters = array();
355 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
356
357 print dol_get_fiche_end();
358
359 print $form->buttonsSaveCancel();
360
361 print '</form>';
362
363 print '<br>';
364}
365
366// End of page
367llxFooter();
368$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:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
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_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return a 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_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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
product_prepare_head($object)
Prepare array with list of tabs.
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.