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