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