dolibarr 24.0.0-beta
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 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 * or see https://www.gnu.org/
23 */
24
31// Load Dolibarr environment
32require '../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
36require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
37
46// Load translation files required by the page
47$langs->loadLangs(array('products', 'languages'));
48
49$id = GETPOSTINT('id');
50$ref = GETPOST('ref', 'alpha');
51$action = GETPOST('action', 'aZ09');
52$cancel = GETPOST('cancel', 'alpha');
53
54// Security check
55$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
56$fieldtype = (!empty($ref) ? 'ref' : 'rowid');
57if ($user->socid) {
58 $socid = $user->socid;
59}
60
61$object = new Product($db);
62if ($id > 0 || !empty($ref)) {
63 $object->fetch($id, $ref);
64}
65
66// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
67$hookmanager->initHooks(array('producttranslationcard', 'globalcard'));
68
69if ($object->id > 0) {
70 if ($object->type == $object::TYPE_PRODUCT) {
71 restrictedArea($user, 'produit', $object->id, 'product&product', '', '');
72 }
73 if ($object->type == $object::TYPE_SERVICE) {
74 restrictedArea($user, 'service', $object->id, 'product&product', '', '');
75 }
76} else {
77 restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
78}
79
80// Permissions
81$usercancreate = (($object->type == Product::TYPE_PRODUCT && $user->hasRight('produit', 'creer')) || ($object->type == Product::TYPE_SERVICE && $user->hasRight('service', 'creer')));
82
83
84/*
85 * Actions
86 */
87
88$parameters = array('id'=>$id, 'ref'=>$ref);
89$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
90if ($reshook < 0) {
91 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
92}
93if (empty($reshook)) {
94 // retour a l'affichage des traduction si annulation
95 if ($cancel == $langs->trans("Cancel")) {
96 $action = '';
97 }
98
99 if ($action == 'delete' && GETPOST('langtodelete', 'alpha') && $usercancreate) {
100 $object->delMultiLangs(GETPOST('langtodelete', 'alpha'), $user);
101 setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
102 header('Location:'.$_SERVER['PHP_SELF'].'?id='.$id);
103 exit;
104 }
105
106 // Add translation
107 if ($action == 'vadd' && $cancel != $langs->trans("Cancel") && $usercancreate) {
108 $current_lang = $langs->getDefaultLang();
109
110 // update de l'objet
111 if (GETPOST("forcelangprod") == $current_lang) {
112 $object->label = GETPOST("libelle");
113 $object->description = dol_htmlcleanlastbr(GETPOST("desc", 'restricthtml'));
114 $object->other = dol_htmlcleanlastbr(GETPOST("other", 'restricthtml'));
115
116 $object->update($object->id, $user, 1); // trigger will be called by setMultiLangs
117 } else {
118 $object->multilangs[GETPOST("forcelangprod")]["label"] = GETPOST("libelle");
119 $object->multilangs[GETPOST("forcelangprod")]["description"] = dol_htmlcleanlastbr(GETPOST("desc", 'restricthtml'));
120 $object->multilangs[GETPOST("forcelangprod")]["other"] = dol_htmlcleanlastbr(GETPOST("other", 'restricthtml'));
121 }
122
123 // save in database
124 if (GETPOST("forcelangprod")) {
125 $result = $object->setMultiLangs($user);
126 } else {
127 $object->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Language"));
128 $result = -1;
129 }
130
131 if ($result > 0) {
132 header('Location:'.$_SERVER['PHP_SELF'].'?id='.$id);
133 exit;
134 } else {
135 $action = 'add';
136 setEventMessages($object->error, $object->errors, 'errors');
137 }
138 }
139
140 // Edit translation
141 if ($action == 'vedit' && $cancel != $langs->trans("Cancel") && $usercancreate) {
142 $current_lang = $langs->getDefaultLang();
143
144 foreach ($object->multilangs as $key => $value) { // Record the new values in the object
145 if ($key == $current_lang) {
146 $object->label = GETPOST("libelle-" . $key);
147 $object->description = dol_htmlcleanlastbr(GETPOST("desc-" . $key, 'restricthtml'));
148 $object->other = dol_htmlcleanlastbr(GETPOST("other-" . $key, 'restricthtml'));
149
150 $object->update($object->id, $user);
151 } else {
152 $object->multilangs[$key]["label"] = GETPOST("libelle-" . $key);
153 $object->multilangs[$key]["description"] = dol_htmlcleanlastbr(GETPOST("desc-" . $key, 'restricthtml'));
154 $object->multilangs[$key]["other"] = dol_htmlcleanlastbr(GETPOST("other-" . $key, 'restricthtml'));
155 }
156 }
157
158 $result = $object->setMultiLangs($user);
159 if ($result > 0) {
160 header('Location:'.$_SERVER['PHP_SELF'].'?id='.$id);
161 exit;
162 } else {
163 $action = 'edit';
164 setEventMessages($object->error, $object->errors, 'errors');
165 }
166 }
167
168 // Delete translation
169 if ($action == 'vdelete' && $cancel != $langs->trans("Cancel") && $usercancreate) {
170 $langtodelete = GETPOST('langdel', 'alpha');
171
172 $result = $object->delMultiLangs($langtodelete, $user);
173 if ($result > 0) {
174 header('Location:'.$_SERVER['PHP_SELF'].'?id='.$id);
175 exit;
176 } else {
177 $action = 'edit';
178 setEventMessages($object->error, $object->errors, 'errors');
179 }
180 }
181}
182
183
184/*
185 * View
186 */
187
188$title = $langs->trans('ProductServiceCard');
189$helpurl = '';
190$shortlabel = dol_trunc($object->label, 16);
191if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) {
192 $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('Translation');
193 $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
194}
195if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) {
196 $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('Translation');
197 $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
198}
199
200llxHeader('', $title, $helpurl, '', 0, 0, '', '', '', 'mod-product page-translation');
201
202$form = new Form($db);
203$formadmin = new FormAdmin($db);
204
205$head = product_prepare_head($object);
206$titre = $langs->trans("CardProduct".$object->type);
207$picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
208
209
210// Calculate $cnt_trans
211$cnt_trans = 0;
212if (!empty($object->multilangs)) {
213 foreach ($object->multilangs as $key => $value) {
214 $cnt_trans++;
215 }
216}
217
218
219print dol_get_fiche_head($head, 'translation', $titre, 0, $picto);
220
221$linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1&type='.$object->type.'">'.$langs->trans("BackToList").'</a>';
222
223$shownav = 1;
224if ($user->socid && !in_array('product', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) {
225 $shownav = 0;
226}
227
228dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref', '', '', '', 0, '', '', 1);
229
230print dol_get_fiche_end();
231
232
233
234/*
235 * Action bar
236 */
237print "\n".'<div class="tabsAction">'."\n";
238
239$parameters = array();
240$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
241if (empty($reshook)) {
242 if ($action == '') {
243 if ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer')) {
244 print '<a class="butAction" href="' . DOL_URL_ROOT . '/product/traduction.php?action=add&token='.newToken().'&id=' . $object->id . '">' . $langs->trans("Add") . '</a>';
245 if ($cnt_trans > 0) {
246 print '<a class="butAction" href="' . DOL_URL_ROOT . '/product/traduction.php?action=edit&token='.newToken().'&id=' . $object->id . '">' . $langs->trans("Modify") . '</a>';
247 }
248 }
249 }
250}
251
252print "\n".'</div>'."\n";
253
254
255
256if ($action == 'edit') {
257 //WYSIWYG Editor
258 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
259
260 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
261 print '<input type="hidden" name="token" value="'.newToken().'">';
262 print '<input type="hidden" name="action" value="vedit">';
263 print '<input type="hidden" name="id" value="'.$object->id.'">';
264
265 if (!empty($object->multilangs)) {
266 $i = 0;
267 foreach ($object->multilangs as $key => $value) {
268 $i++;
269
270 $s = picto_from_langcode((string) $key);
271 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>';
272
273 print '<div class="underbanner clearboth"></div>';
274 print '<table class="border centpercent">';
275 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans('Label').'</td><td><input name="libelle-'.$key.'" size="40" value="'.dol_escape_htmltag($object->multilangs[$key]["label"]).'"></td></tr>';
276 print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
277 $doleditor = new DolEditor("desc-$key", $object->multilangs[$key]["description"], '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_DETAILS'), ROWS_3, '90%');
278 $doleditor->Create();
279 print '</td></tr>';
280 if (getDolGlobalString('PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION')) {
281 print '<tr><td class="tdtop">'.$langs->trans("NotePrivate").'</td><td>';
282 $doleditor = new DolEditor("other-$key", $object->multilangs[$key]["other"], '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_DETAILS'), ROWS_3, '90%');
283 $doleditor->Create();
284 }
285 print '</td></tr>';
286 print '</table>';
287 }
288 }
289
290 $parameters = array();
291 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
292
293 print '<br>';
294
295 print $form->buttonsSaveCancel();
296
297 print '</form>';
298} elseif ($action != 'add') {
299 if (!empty($object->multilangs)) {
300 $i = 0;
301 foreach ($object->multilangs as $key => $value) {
302 $i++;
303
304 $s = picto_from_langcode((string) $key);
305 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>';
306
307 print '<div class="fichecenter">';
308 print '<div class="underbanner clearboth"></div>';
309 print '<table class="border centpercent">';
310 print '<tr><td class="titlefieldcreate">'.$langs->trans('Label').'</td><td>'.$object->multilangs[$key]["label"].'</td></tr>';
311 print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>'.$object->multilangs[$key]["description"].'</td></tr>';
312 if (getDolGlobalString('PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION')) {
313 print '<tr><td>'.$langs->trans("NotePrivate").'</td><td>'.$object->multilangs[$key]["other"].'</td></tr>';
314 }
315 print '</table>';
316 print '</div>';
317 }
318 }
319 if (!$cnt_trans && $action != 'add') {
320 print '<div class="opacitymedium">'.$langs->trans('NoTranslation').'</div>';
321 }
322}
323
324
325
326/*
327 * Form to add a new translation
328 */
329
330if ($action == 'add' && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
331 //WYSIWYG Editor
332 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
333
334 print '<br>';
335 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
336 print '<input type="hidden" name="token" value="'.newToken().'">';
337 print '<input type="hidden" name="action" value="vadd">';
338 print '<input type="hidden" name="id" value="'.GETPOSTINT("id").'">';
339
340 print dol_get_fiche_head();
341
342 print '<table class="border centpercent">';
343 print '<tr><td class="tdtop titlefieldcreate fieldrequired">'.$langs->trans('Language').'</td><td>';
344 print $formadmin->select_language(GETPOST('forcelangprod'), 'forcelangprod', 0, $object->multilangs, 1);
345 print '</td></tr>';
346 print '<tr><td class="tdtop fieldrequired">'.$langs->trans('Label').'</td><td><input name="libelle" size="40"></td></tr>';
347 print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
348 $doleditor = new DolEditor('desc', '', '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_DETAILS'), ROWS_3, '90%');
349 $doleditor->Create();
350 print '</td></tr>';
351 // Other field (not used)
352 if (getDolGlobalString('PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION')) {
353 print '<tr><td class="tdtop">'.$langs->trans('NotePrivate').'</td><td>';
354 $doleditor = new DolEditor('other', '', '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_DETAILS'), ROWS_3, '90%');
355 $doleditor->Create();
356 print '</td></tr>';
357 }
358 print '</table>';
359
360 $parameters = array();
361 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
362
363 print dol_get_fiche_end();
364
365 print $form->buttonsSaveCancel();
366
367 print '</form>';
368
369 print '<br>';
370}
371
372// End of page
373llxFooter();
374$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
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.
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 a 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.