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