dolibarr  16.0.1
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  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  * or see https://www.gnu.org/
20  */
21 
28 require '../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
33 
34 // Load translation files required by the page
35 $langs->loadLangs(array('products', 'languages'));
36 
37 $id = GETPOST('id', 'int');
38 $ref = GETPOST('ref', 'alpha');
39 $action = GETPOST('action', 'aZ09');
40 $cancel = GETPOST('cancel', 'alpha');
41 
42 // Security check
43 $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
44 $fieldtype = (!empty($ref) ? 'ref' : 'rowid');
45 if ($user->socid) {
46  $socid = $user->socid;
47 }
48 
49 if ($id > 0 || !empty($ref)) {
50  $object = new Product($db);
51  $object->fetch($id, $ref);
52 }
53 
54 if ($object->id > 0) {
55  if ($object->type == $object::TYPE_PRODUCT) {
56  restrictedArea($user, 'produit', $object->id, 'product&product', '', '');
57  }
58  if ($object->type == $object::TYPE_SERVICE) {
59  restrictedArea($user, 'service', $object->id, 'product&product', '', '');
60  }
61 } else {
62  restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
63 }
64 
65 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
66 $hookmanager->initHooks(array('producttranslationcard', 'globalcard'));
67 
68 
69 /*
70  * Actions
71  */
72 
73 $parameters = array('id'=>$id, 'ref'=>$ref);
74 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
75 if ($reshook < 0) {
76  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
77 }
78 if (empty($reshook)) {
79  // retour a l'affichage des traduction si annulation
80  if ($cancel == $langs->trans("Cancel")) {
81  $action = '';
82  }
83 
84  if ($action == 'delete' && GETPOST('langtodelete', 'alpha')) {
85  $object = new Product($db);
86  $object->fetch($id);
87  $object->delMultiLangs(GETPOST('langtodelete', 'alpha'), $user);
88  setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
89  $action = '';
90  }
91 
92  // Add translation
93  if ($action == 'vadd' && $cancel != $langs->trans("Cancel") && ($user->rights->produit->creer || $user->rights->service->creer)) {
94  $object = new Product($db);
95  $object->fetch($id);
96  $current_lang = $langs->getDefaultLang();
97 
98  // update de l'objet
99  if (GETPOST("forcelangprod") == $current_lang) {
100  $object->label = GETPOST("libelle");
101  $object->description = dol_htmlcleanlastbr(GETPOST("desc", 'restricthtml'));
102  $object->other = dol_htmlcleanlastbr(GETPOST("other", 'restricthtml'));
103 
104  $object->update($object->id, $user);
105  } else {
106  $object->multilangs[GETPOST("forcelangprod")]["label"] = GETPOST("libelle");
107  $object->multilangs[GETPOST("forcelangprod")]["description"] = dol_htmlcleanlastbr(GETPOST("desc", 'restricthtml'));
108  $object->multilangs[GETPOST("forcelangprod")]["other"] = dol_htmlcleanlastbr(GETPOST("other", 'restricthtml'));
109  }
110 
111  // save in database
112  if (GETPOST("forcelangprod")) {
113  $result = $object->setMultiLangs($user);
114  } else {
115  $object->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Language"));
116  $result = -1;
117  }
118 
119  if ($result > 0) {
120  $action = '';
121  } else {
122  $action = 'add';
123  setEventMessages($object->error, $object->errors, 'errors');
124  }
125  }
126 
127  // Edit translation
128  if ($action == 'vedit' && $cancel != $langs->trans("Cancel") && ($user->rights->produit->creer || $user->rights->service->creer)) {
129  $object = new Product($db);
130  $object->fetch($id);
131  $current_lang = $langs->getDefaultLang();
132 
133  foreach ($object->multilangs as $key => $value) { // enregistrement des nouvelles valeurs dans l'objet
134  if ($key == $current_lang) {
135  $object->label = GETPOST("libelle-" . $key);
136  $object->description = dol_htmlcleanlastbr(GETPOST("desc-" . $key, 'restricthtml'));
137  $object->other = dol_htmlcleanlastbr(GETPOST("other-" . $key, 'restricthtml'));
138  } else {
139  $object->multilangs[$key]["label"] = GETPOST("libelle-" . $key);
140  $object->multilangs[$key]["description"] = dol_htmlcleanlastbr(GETPOST("desc-" . $key, 'restricthtml'));
141  $object->multilangs[$key]["other"] = dol_htmlcleanlastbr(GETPOST("other-" . $key, 'restricthtml'));
142  }
143  }
144 
145  $result = $object->setMultiLangs($user);
146  if ($result > 0) {
147  $action = '';
148  } else {
149  $action = 'edit';
150  setEventMessages($object->error, $object->errors, 'errors');
151  }
152  }
153 
154  // Delete translation
155  if ($action == 'vdelete' && $cancel != $langs->trans("Cancel") && ($user->rights->produit->creer || $user->rights->service->creer)) {
156  $object = new Product($db);
157  $object->fetch($id);
158  $langtodelete = GETPOST('langdel', 'alpha');
159 
160  $result = $object->delMultiLangs($langtodelete, $user);
161  if ($result > 0) {
162  $action = '';
163  } else {
164  $action = 'edit';
165  setEventMessages($object->error, $object->errors, 'errors');
166  }
167  }
168 }
169 
170 $object = new Product($db);
171 $result = $object->fetch($id, $ref);
172 
173 
174 /*
175  * View
176  */
177 
178 $title = $langs->trans('ProductServiceCard');
179 $helpurl = '';
180 $shortlabel = dol_trunc($object->label, 16);
181 if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) {
182  $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('Translation');
183  $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
184 }
185 if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) {
186  $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('Translation');
187  $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
188 }
189 
190 llxHeader('', $title, $helpurl);
191 
192 $form = new Form($db);
193 $formadmin = new FormAdmin($db);
194 
195 $head = product_prepare_head($object);
196 $titre = $langs->trans("CardProduct".$object->type);
197 $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
198 
199 
200 // Calculate $cnt_trans
201 $cnt_trans = 0;
202 if (!empty($object->multilangs)) {
203  foreach ($object->multilangs as $key => $value) {
204  $cnt_trans++;
205  }
206 }
207 
208 
209 print dol_get_fiche_head($head, 'translation', $titre, 0, $picto);
210 
211 $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
212 
213 $shownav = 1;
214 if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
215  $shownav = 0;
216 }
217 
218 dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref', '', '', '', 0, '', '', 1);
219 
220 print dol_get_fiche_end();
221 
222 
223 
224 /*
225  * Action bar
226  */
227 print "\n".'<div class="tabsAction">'."\n";
228 
229 $parameters = array();
230 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
231 if (empty($reshook)) {
232  if ($action == '') {
233  if ($user->rights->produit->creer || $user->rights->service->creer) {
234  print '<a class="butAction" href="' . DOL_URL_ROOT . '/product/traduction.php?action=add&token='.newToken().'&id=' . $object->id . '">' . $langs->trans("Add") . '</a>';
235  if ($cnt_trans > 0) {
236  print '<a class="butAction" href="' . DOL_URL_ROOT . '/product/traduction.php?action=edit&token='.newToken().'&id=' . $object->id . '">' . $langs->trans("Modify") . '</a>';
237  }
238  }
239  }
240 }
241 
242 print "\n".'</div>'."\n";
243 
244 
245 
246 if ($action == 'edit') {
247  //WYSIWYG Editor
248  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
249 
250  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
251  print '<input type="hidden" name="token" value="'.newToken().'">';
252  print '<input type="hidden" name="action" value="vedit">';
253  print '<input type="hidden" name="id" value="'.$object->id.'">';
254 
255  if (!empty($object->multilangs)) {
256  $i = 0;
257  foreach ($object->multilangs as $key => $value) {
258  $i++;
259 
260  $s = picto_from_langcode($key);
261  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>';
262 
263  print '<div class="underbanner clearboth"></div>';
264  print '<table class="border centpercent">';
265  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>';
266  print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
267  $doleditor = new DolEditor("desc-$key", $object->multilangs[$key]["description"], '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_PRODUCTDESC'), ROWS_3, '90%');
268  $doleditor->Create();
269  print '</td></tr>';
270  if (!empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) {
271  print '<tr><td class="tdtop">'.$langs->trans('Other').' ('.$langs->trans("NotUsed").')</td><td>';
272  $doleditor = new DolEditor("other-$key", $object->multilangs[$key]["other"], '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_PRODUCTDESC'), ROWS_3, '90%');
273  $doleditor->Create();
274  }
275  print '</td></tr>';
276  print '</table>';
277  }
278  }
279 
280  $parameters = array();
281  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
282 
283  print '<br>';
284 
285  print $form->buttonsSaveCancel();
286 
287  print '</form>';
288 } elseif ($action != 'add') {
289  if (!empty($object->multilangs)) {
290  $i = 0;
291  foreach ($object->multilangs as $key => $value) {
292  $i++;
293 
294  $s = picto_from_langcode($key);
295  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>';
296 
297  print '<div class="fichecenter">';
298  print '<div class="underbanner clearboth"></div>';
299  print '<table class="border centpercent">';
300  print '<tr><td class="titlefieldcreate">'.$langs->trans('Label').'</td><td>'.$object->multilangs[$key]["label"].'</td></tr>';
301  print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>'.$object->multilangs[$key]["description"].'</td></tr>';
302  if (!empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) {
303  print '<tr><td>'.$langs->trans('Other').' ('.$langs->trans("NotUsed").')</td><td>'.$object->multilangs[$key]["other"].'</td></tr>';
304  }
305  print '</table>';
306  print '</div>';
307  }
308  }
309  if (!$cnt_trans && $action != 'add') {
310  print '<div class="opacitymedium">'.$langs->trans('NoTranslation').'</div>';
311  }
312 }
313 
314 
315 
316 /*
317  * Form to add a new translation
318  */
319 
320 if ($action == 'add' && ($user->rights->produit->creer || $user->rights->service->creer)) {
321  //WYSIWYG Editor
322  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
323 
324  print '<br>';
325  print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
326  print '<input type="hidden" name="token" value="'.newToken().'">';
327  print '<input type="hidden" name="action" value="vadd">';
328  print '<input type="hidden" name="id" value="'.GETPOST("id", 'int').'">';
329 
330  print dol_get_fiche_head();
331 
332  print '<table class="border centpercent">';
333  print '<tr><td class="tdtop titlefieldcreate fieldrequired">'.$langs->trans('Language').'</td><td>';
334  print $formadmin->select_language(GETPOST('forcelangprod'), 'forcelangprod', 0, $object->multilangs, 1);
335  print '</td></tr>';
336  print '<tr><td class="tdtop fieldrequired">'.$langs->trans('Label').'</td><td><input name="libelle" size="40"></td></tr>';
337  print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
338  $doleditor = new DolEditor('desc', '', '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_PRODUCTDESC'), ROWS_3, '90%');
339  $doleditor->Create();
340  print '</td></tr>';
341  // Other field (not used)
342  if (!empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) {
343  print '<tr><td class="tdtop">'.$langs->trans('Other').' ('.$langs->trans("NotUsed").'</td><td>';
344  $doleditor = new DolEditor('other', '', '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_PRODUCTDESC'), ROWS_3, '90%');
345  $doleditor->Create();
346  print '</td></tr>';
347  }
348  print '</table>';
349 
350  $parameters = array();
351  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
352 
353  print dol_get_fiche_end();
354 
355  print $form->buttonsSaveCancel();
356 
357  print '</form>';
358 
359  print '<br>';
360 }
361 
362 // End of page
363 llxFooter();
364 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
Definition: card.php:142
Class to manage products or services.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
const TYPE_SERVICE
Service.
const TYPE_PRODUCT
Regular product.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
Class to generate html code for admin pages.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
restrictedArea($user, $features, $objectid=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.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage a WYSIWYG editor.
dol_trunc($string, $size=40, $trunc= 'right', $stringencoding= 'UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;…&#39; if string larger than length. ...
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:73
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.
picto_from_langcode($codelang, $moreatt= '', $notitlealt=0)
Return img flag of country for a language code or country code.
product_prepare_head($object)
Prepare array with list of tabs.
Definition: product.lib.php:35