dolibarr  7.0.0-beta
traduction.php
1 <?php
2 /* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
3  * Copyright (C) 2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
4  * Copyright (C) 2010-2016 Destailleur Laurent <eldy@users.sourceforge.net>
5  * Copyright (C) 2015 RaphaĆ«l Doursenaud <rdoursenaud@gpcsolutions.fr>
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 <http://www.gnu.org/licenses/>.
19  * or see http://www.gnu.org/
20  */
21 
28 require '../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
34 
35 $langs->load("categories");
36 $langs->load("languages");
37 
38 $id = GETPOST('id', 'int');
39 $ref = GETPOST('ref', 'alpha');
40 $action = GETPOST('action','alpha');
41 $cancel = GETPOST('cancel','alpha');
42 $type = GETPOST('type','aZ09');
43 
44 if (is_numeric($type)) $type=Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
45 
46 // Security check
47 $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
48 $fieldtype = (! empty($ref) ? 'ref' : 'rowid');
49 
50 if ($id == "")
51 {
52  dol_print_error('','Missing parameter id');
53  exit();
54 }
55 
56 // Security check
57 $result = restrictedArea($user, 'categorie', $id, '&category');
58 
59 $object = new Categorie($db);
60 
61 
62 /*
63  * Actions
64  */
65 
66 // retour a l'affichage des traduction si annulation
67 if ($cancel == $langs->trans("Cancel"))
68 {
69  $action = '';
70 }
71 
72 
73 // Validation de l'ajout
74 if ($action == 'vadd' &&
75 $cancel != $langs->trans("Cancel") &&
76 ($user->rights->categorie->creer ))
77 {
78  $object->fetch($id);
79  $current_lang = $langs->getDefaultLang();
80 
81  // update de l'objet
82  if ( $_POST["forcelangprod"] == $current_lang )
83  {
84  $object->label = $_POST["libelle"];
85  $object->description = dol_htmlcleanlastbr($_POST["desc"]);
86  }
87  else
88  {
89  $object->multilangs[$_POST["forcelangprod"]]["label"] = $_POST["libelle"];
90  $object->multilangs[$_POST["forcelangprod"]]["description"] = dol_htmlcleanlastbr($_POST["desc"]);
91  }
92 
93  // sauvegarde en base
94  if ( $object->setMultiLangs($user) > 0 )
95  {
96  $action = '';
97  }
98  else
99  {
100  $action = 'add';
101  setEventMessages($object->error, $object->errors, 'errors');
102  }
103 }
104 
105 // Validation de l'edition
106 if ($action == 'vedit' &&
107 $cancel != $langs->trans("Cancel") &&
108 ($user->rights->categorie->creer))
109 {
110  $object->fetch($id);
111  $current_lang = $langs->getDefaultLang();
112 
113  foreach ( $object->multilangs as $key => $value ) // enregistrement des nouvelles valeurs dans l'objet
114  {
115  if ( $key == $current_lang )
116  {
117  $object->label = $_POST["libelle-".$key];
118  $object->description = dol_htmlcleanlastbr($_POST["desc-".$key]);
119  }
120  else
121  {
122  $object->multilangs[$key]["label"] = $_POST["libelle-".$key];
123  $object->multilangs[$key]["description"] = dol_htmlcleanlastbr($_POST["desc-".$key]);
124  }
125  }
126 
127  if ( $object->setMultiLangs($user) > 0 )
128  {
129  $action = '';
130  }
131  else
132  {
133  $action = 'edit';
134  setEventMessages($object->error, $object->errors, 'errors');
135  }
136 }
137 
138 $result = $object->fetch($id,$ref);
139 
140 
141 /*
142  * View
143  */
144 
145 llxHeader("","",$langs->trans("Translation"));
146 
147 $form = new Form($db);
148 $formadmin=new FormAdmin($db);
149 $formother = new FormOther($db);
150 
151 if ($type == Categorie::TYPE_PRODUCT) $title=$langs->trans("ProductsCategoryShort");
152 elseif ($type == Categorie::TYPE_SUPPLIER) $title=$langs->trans("SuppliersCategoryShort");
153 elseif ($type == Categorie::TYPE_CUSTOMER) $title=$langs->trans("CustomersCategoryShort");
154 elseif ($type == Categorie::TYPE_MEMBER) $title=$langs->trans("MembersCategoryShort");
155 elseif ($type == Categorie::TYPE_CONTACT) $title=$langs->trans("ContactCategoriesShort");
156 elseif ($type == Categorie::TYPE_ACCOUNT) $title=$langs->trans("AccountsCategoriesShort");
157 elseif ($type == Categorie::TYPE_PROJECT) $title=$langs->trans("ProjectsCategoriesShort");
158 elseif ($type == Categorie::TYPE_USER) $title=$langs->trans("UsersCategoriesShort");
159 else $title=$langs->trans("Category");
160 
161 $head = categories_prepare_head($object,$type);
162 
163 // Calculate $cnt_trans
164 $cnt_trans = 0;
165 if (! empty($object->multilangs))
166 {
167  foreach ($object->multilangs as $key => $value)
168  {
169  $cnt_trans++;
170  }
171 }
172 
173 dol_fiche_head($head, 'translation', $title, -1, 'category');
174 
175 $linkback = '<a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("BackToList").'</a>';
176 
177 $object->ref = $object->label;
178 $morehtmlref='<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> ';
179 $ways = $object->print_all_ways(" &gt;&gt; ", '', 1);
180 foreach ($ways as $way)
181 {
182  $morehtmlref.=$way."<br>\n";
183 }
184 $morehtmlref.='</div>';
185 
186 dol_banner_tab($object, 'ref', $linkback, ($user->societe_id?0:1), 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
187 
188 print '<br>';
189 
190 print '<div class="fichecenter">';
191 print '<div class="underbanner clearboth"></div>';
192 
193 print '<table class="border" width="100%">';
194 
195 // Description
196 print '<tr><td class="titlefield notopnoleft">';
197 print $langs->trans("Description").'</td><td>';
198 print dol_htmlentitiesbr($object->description);
199 print '</td></tr>';
200 
201 // Color
202 print '<tr><td class="notopnoleft">';
203 print $langs->trans("Color").'</td><td>';
204 print $formother->showColor($object->color);
205 print '</td></tr>';
206 
207 print '</table>';
208 print '</div>';
209 
210 dol_fiche_end();
211 
212 
213 
214 
215 /* ************************************************************************** */
216 /* */
217 /* Barre d'action */
218 /* */
219 /* ************************************************************************** */
220 
221 print "\n<div class=\"tabsAction\">\n";
222 
223 if ($action == '')
224 {
225  if ($user->rights->produit->creer || $user->rights->service->creer)
226  {
227  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=add&id='.$object->id.'">'.$langs->trans("Add").'</a>';
228  if ($cnt_trans > 0) print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&id='.$object->id.'">'.$langs->trans("Update").'</a>';
229  }
230 }
231 
232 print "\n</div>\n";
233 
234 
235 
236 if ($action == 'edit')
237 {
238  //WYSIWYG Editor
239  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
240 
241  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
242  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
243  print '<input type="hidden" name="action" value="vedit">';
244  print '<input type="hidden" name="id" value="'.$object->id.'">';
245 
246  if (! empty($object->multilangs))
247  {
248  foreach ($object->multilangs as $key => $value)
249  {
250  print "<br><b><u>".$langs->trans('Language_'.$key)." :</u></b><br>";
251  print '<table class="border" width="100%">';
252  print '<tr><td class="titlefield fieldrequired">'.$langs->trans('Label').'</td><td><input name="libelle-'.$key.'" size="40" value="'.$object->multilangs[$key]["label"].'"></td></tr>';
253  print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
254  $doleditor = new DolEditor("desc-$key", $object->multilangs[$key]["description"], '', 160, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, ROWS_3,'90%');
255  $doleditor->Create();
256  print '</td></tr>';
257 
258  print '</tr>';
259  print '</table>';
260  }
261  }
262 
263  print '<br>';
264 
265  print '<div class="center">';
266  print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
267  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
268  print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
269  print '</div>';
270 
271  print '</form>';
272 
273 }
274 else if ($action != 'add')
275 {
276  if ($cnt_trans) print '<div class="underbanner clearboth"></div>';
277 
278  if (! empty($object->multilangs))
279  {
280  foreach ($object->multilangs as $key => $value)
281  {
282  $s=picto_from_langcode($key);
283  print '<table class="border" width="100%">';
284  print '<tr class="liste_titre"><td colspan="2">'.($s?$s.' ':'')." <b>".$langs->trans('Language_'.$key).":</b> ".'<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&langtodelete='.$key.'">'.img_delete('', '').'</a></td></tr>';
285  print '<tr><td class="titlefield">'.$langs->trans('Label').'</td><td>'.$object->multilangs[$key]["label"].'</td></tr>';
286  print '<tr><td>'.$langs->trans('Description').'</td><td>'.$object->multilangs[$key]["description"].'</td></tr>';
287  if (! empty($conf->global->CATEGORY_USE_OTHER_FIELD_IN_TRANSLATION))
288  {
289  print '<tr><td>'.$langs->trans('Other').' ('.$langs->trans("NotUsed").')</td><td>'.$object->multilangs[$key]["other"].'</td></tr>';
290  }
291  print '</table>';
292  }
293  }
294  if (! $cnt_trans && $action != 'add') print '<div class="opacitymedium">'. $langs->trans('NoTranslation').'</div>';
295 }
296 
297 
298 /*
299  * Form to add a new translation
300  */
301 
302 if ($action == 'add' && ($user->rights->produit->creer || $user->rights->service->creer))
303 {
304  //WYSIWYG Editor
305  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
306 
307  print '<br>';
308  print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
309  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
310  print '<input type="hidden" name="action" value="vadd">';
311  print '<input type="hidden" name="id" value="'.$id.'">';
312 
313  print '<table class="border" width="100%">';
314  print '<tr><td class="titlefield fieldrequired">'.$langs->trans('Translation').'</td><td>';
315  print $formadmin->select_language('','forcelangprod',0,$object->multilangs);
316  print '</td></tr>';
317  print '<tr><td class="fieldrequired">'.$langs->trans('Label').'</td><td><input name="libelle" size="40"></td></tr>';
318  print '<tr><td>'.$langs->trans('Description').'</td><td>';
319  $doleditor = new DolEditor('desc', '', '', 160, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, ROWS_3,'90%');
320  $doleditor->Create();
321  print '</td></tr>';
322 
323  print '</tr>';
324  print '</table>';
325 
326  print '<div class="center">';
327  print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
328  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
329  print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
330  print '</div>';
331 
332  print '</form>';
333 
334  print '<br>';
335 }
336 
337 llxFooter();
338 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(!GETPOST('transkey')&&!GETPOST('transphrase')) else
View.
Definition: notice.php:43
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
if(GETPOST('cancel','alpha')) if(!GETPOST('confirmmassaction','alpha')&&$massaction!= 'presend'&&$massaction!= 'confirm_presend')
Draft customers invoices.
Definition: list.php:147
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.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to generate html code for admin pages.
Class to manage generation of HTML components Only common components must be here.
Class to manage categories.
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
dol_fiche_end($notab=0)
Show tab footer of a card.
Classe permettant la generation de composants html autre Only common components are here...
llxHeader()
Empty header.
Definition: wrapper.php:46
img_delete($titlealt= 'default', $other= 'class="pictodelete"')
Show delete logo.
print
Draft customers invoices.
Definition: index.php:91
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
Class to manage a WYSIWYG editor.
categories_prepare_head($object, $type)
Prepare array with list of tabs.
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.
picto_from_langcode($codelang, $moreatt= '')
Return img flag of country for a language code or country code.