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