dolibarr  13.0.2
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) $socid = $user->socid;
46 $result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
47 
48 
49 /*
50  * Actions
51  */
52 
53 // retour a l'affichage des traduction si annulation
54 if ($cancel == $langs->trans("Cancel"))
55 {
56  $action = '';
57 }
58 
59 if ($action == 'delete' && GETPOST('langtodelete', 'alpha'))
60 {
61  $object = new Product($db);
62  $object->fetch($id);
63  $object->delMultiLangs(GETPOST('langtodelete', 'alpha'), $user);
64 }
65 
66 // Add translation
67 if ($action == 'vadd' &&
68 $cancel != $langs->trans("Cancel") &&
69 ($user->rights->produit->creer || $user->rights->service->creer))
70 {
71  $object = new Product($db);
72  $object->fetch($id);
73  $current_lang = $langs->getDefaultLang();
74 
75  // update de l'objet
76  if ($_POST["forcelangprod"] == $current_lang) {
77  $object->label = $_POST["libelle"];
78  $object->description = dol_htmlcleanlastbr($_POST["desc"]);
79  $object->other = dol_htmlcleanlastbr($_POST["other"]);
80  $object->update($object->id, $user);
81  } else {
82  $object->multilangs[$_POST["forcelangprod"]]["label"] = $_POST["libelle"];
83  $object->multilangs[$_POST["forcelangprod"]]["description"] = dol_htmlcleanlastbr($_POST["desc"]);
84  $object->multilangs[$_POST["forcelangprod"]]["other"] = dol_htmlcleanlastbr($_POST["other"]);
85  }
86 
87  // sauvegarde en base
88  if ($object->setMultiLangs($user) > 0) {
89  $action = '';
90  } else {
91  $action = 'add';
92  setEventMessages($object->error, $object->errors, 'errors');
93  }
94 }
95 
96 // Edit translation
97 if ($action == 'vedit' &&
98 $cancel != $langs->trans("Cancel") &&
99 ($user->rights->produit->creer || $user->rights->service->creer))
100 {
101  $object = new Product($db);
102  $object->fetch($id);
103  $current_lang = $langs->getDefaultLang();
104 
105  foreach ($object->multilangs as $key => $value) // enregistrement des nouvelles valeurs dans l'objet
106  {
107  if ($key == $current_lang)
108  {
109  $object->label = $_POST["libelle-".$key];
110  $object->description = dol_htmlcleanlastbr($_POST["desc-".$key]);
111  $object->other = dol_htmlcleanlastbr($_POST["other-".$key]);
112  } else {
113  $object->multilangs[$key]["label"] = $_POST["libelle-".$key];
114  $object->multilangs[$key]["description"] = dol_htmlcleanlastbr($_POST["desc-".$key]);
115  $object->multilangs[$key]["other"] = dol_htmlcleanlastbr($_POST["other-".$key]);
116  }
117  }
118 
119  if ($object->setMultiLangs($user) > 0)
120  {
121  $action = '';
122  } else {
123  $action = 'edit';
124  setEventMessages($object->error, $object->errors, 'errors');
125  }
126 }
127 
128 // Delete translation
129 if ($action == 'vdelete' &&
130 $cancel != $langs->trans("Cancel") &&
131 ($user->rights->produit->creer || $user->rights->service->creer))
132 {
133  $object = new Product($db);
134  $object->fetch($id);
135  $langtodelete = GETPOST('langdel', 'alpha');
136 
137 
138  if ($object->delMultiLangs($langtodelete, $user) > 0)
139  {
140  $action = '';
141  } else {
142  $action = 'edit';
143  setEventMessages($object->error, $object->errors, 'errors');
144  }
145 }
146 
147 $object = new Product($db);
148 $result = $object->fetch($id, $ref);
149 
150 
151 /*
152  * View
153  */
154 
155 $title = $langs->trans('ProductServiceCard');
156 $helpurl = '';
157 $shortlabel = dol_trunc($object->label, 16);
158 if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT))
159 {
160  $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('Translation');
161  $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
162 }
163 if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE))
164 {
165  $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('Translation');
166  $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
167 }
168 
169 llxHeader('', $title, $helpurl);
170 
171 $form = new Form($db);
172 $formadmin = new FormAdmin($db);
173 
174 $head = product_prepare_head($object);
175 $titre = $langs->trans("CardProduct".$object->type);
176 $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
177 
178 
179 // Calculate $cnt_trans
180 $cnt_trans = 0;
181 if (!empty($object->multilangs))
182 {
183  foreach ($object->multilangs as $key => $value)
184  {
185  $cnt_trans++;
186  }
187 }
188 
189 
190 print dol_get_fiche_head($head, 'translation', $titre, 0, $picto);
191 
192 $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
193 
194 $shownav = 1;
195 if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0;
196 
197 dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref', '', '', '', 0, '', '', 1);
198 
200 
201 
202 
203 /* ************************************************************************** */
204 /* */
205 /* Barre d'action */
206 /* */
207 /* ************************************************************************** */
208 
209 print "\n<div class=\"tabsAction\">\n";
210 
211 if ($action == '')
212 {
213  if ($user->rights->produit->creer || $user->rights->service->creer)
214  {
215  print '<a class="butAction" href="'.DOL_URL_ROOT.'/product/traduction.php?action=add&id='.$object->id.'">'.$langs->trans("Add").'</a>';
216  if ($cnt_trans > 0) print '<a class="butAction" href="'.DOL_URL_ROOT.'/product/traduction.php?action=edit&id='.$object->id.'">'.$langs->trans("Update").'</a>';
217  }
218 }
219 
220 print "\n</div>\n";
221 
222 
223 
224 if ($action == 'edit')
225 {
226  //WYSIWYG Editor
227  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
228 
229  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
230  print '<input type="hidden" name="token" value="'.newToken().'">';
231  print '<input type="hidden" name="action" value="vedit">';
232  print '<input type="hidden" name="id" value="'.$object->id.'">';
233 
234  if (!empty($object->multilangs))
235  {
236  foreach ($object->multilangs as $key => $value)
237  {
238  $s = picto_from_langcode($key);
239  print "<br>".($s ? $s.' ' : '')." <b>".$langs->trans('Language_'.$key).":</b> ".'<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'&langtodelete='.$key.'">'.img_delete('', 'class="valigntextbottom"')."</a><br>";
240 
241  print '<div class="underbanner clearboth"></div>';
242  print '<table class="border centpercent">';
243  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>';
244  print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
245  $doleditor = new DolEditor("desc-$key", $object->multilangs[$key]["description"], '', 160, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, ROWS_3, '90%');
246  $doleditor->Create();
247  print '</td></tr>';
248  if (!empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION))
249  {
250  print '<tr><td class="tdtop">'.$langs->trans('Other').' ('.$langs->trans("NotUsed").')</td><td>';
251  $doleditor = new DolEditor("other-$key", $object->multilangs[$key]["other"], '', 160, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, ROWS_3, '90%');
252  $doleditor->Create();
253  }
254  print '</td></tr>';
255  print '</table>';
256  }
257  }
258 
259  print '<br>';
260 
261  print '<div class="center">';
262  print '<input type="submit" class="button button-save" value="'.$langs->trans("Save").'">';
263  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
264  print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
265  print '</div>';
266 
267  print '</form>';
268 } elseif ($action != 'add')
269 {
270  if (!empty($object->multilangs))
271  {
272  foreach ($object->multilangs as $key => $value)
273  {
274  $s = picto_from_langcode($key);
275  print ($s ? $s.' ' : '')." <b>".$langs->trans('Language_'.$key).":</b> ".'<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'&langtodelete='.$key.'">'.img_delete('', 'class="valigntextbottom"').'</a>';
276 
277  print '<div class="fichecenter">';
278  print '<div class="underbanner clearboth"></div>';
279  print '<table class="border centpercent">';
280  print '<tr><td class="titlefieldcreate">'.$langs->trans('Label').'</td><td>'.$object->multilangs[$key]["label"].'</td></tr>';
281  print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>'.$object->multilangs[$key]["description"].'</td></tr>';
282  if (!empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION))
283  {
284  print '<tr><td>'.$langs->trans('Other').' ('.$langs->trans("NotUsed").')</td><td>'.$object->multilangs[$key]["other"].'</td></tr>';
285  }
286  print '</table>';
287  print '</div>';
288  }
289  }
290  if (!$cnt_trans && $action != 'add') print '<div class="opacitymedium">'.$langs->trans('NoTranslation').'</div>';
291 }
292 
293 
294 
295 /*
296  * Form to add a new translation
297  */
298 
299 if ($action == 'add' && ($user->rights->produit->creer || $user->rights->service->creer))
300 {
301  //WYSIWYG Editor
302  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
303 
304  print '<br>';
305  print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
306  print '<input type="hidden" name="token" value="'.newToken().'">';
307  print '<input type="hidden" name="action" value="vadd">';
308  print '<input type="hidden" name="id" value="'.GETPOST("id", 'int').'">';
309 
311 
312  print '<table class="border centpercent">';
313  print '<tr><td class="tdtop titlefieldcreate fieldrequired">'.$langs->trans('Language').'</td><td>';
314  print $formadmin->select_language('', 'forcelangprod', 0, $object->multilangs, 1);
315  print '</td></tr>';
316  print '<tr><td class="tdtop fieldrequired">'.$langs->trans('Label').'</td><td><input name="libelle" size="40"></td></tr>';
317  print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
318  $doleditor = new DolEditor('desc', '', '', 160, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, ROWS_3, '90%');
319  $doleditor->Create();
320  print '</td></tr>';
321  // Other field (not used)
322  if (!empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION))
323  {
324  print '<tr><td class="tdtop">'.$langs->trans('Other').' ('.$langs->trans("NotUsed").'</td><td>';
325  $doleditor = new DolEditor('other', '', '', 160, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, ROWS_3, '90%');
326  $doleditor->Create();
327  print '</td></tr>';
328  }
329  print '</table>';
330 
332 
333  print '<div class="center">';
334  print '<input type="submit" class="button button-save" value="'.$langs->trans("Save").'">';
335  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
336  print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
337  print '</div>';
338 
339  print '</form>';
340 
341  print '<br>';
342 }
343 
344 // End of page
345 llxFooter();
346 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage products or services.
const TYPE_SERVICE
Service.
const TYPE_PRODUCT
Regular product.
Class to generate html code for admin pages.
llxHeader()
Empty header.
Definition: wrapper.php:45
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)
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.
print
Draft customers invoices.
Definition: index.php:89
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:59
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.
picto_from_langcode($codelang, $moreatt= '')
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
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...