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