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