traduction.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <?php
  2. /* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.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. /**
  22. * \file htdocs/product/traduction.php
  23. * \ingroup product
  24. * \brief Page de traduction des produits
  25. */
  26. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  32. // Load translation files required by the page
  33. $langs->loadLangs(array('categories', 'languages'));
  34. $id = GETPOST('id', 'int');
  35. $ref = GETPOST('ref', 'alpha');
  36. $action = GETPOST('action','alpha');
  37. $cancel = GETPOST('cancel','alpha');
  38. $type = GETPOST('type','aZ09');
  39. if (is_numeric($type)) $type=Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
  40. // Security check
  41. $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
  42. $fieldtype = (! empty($ref) ? 'ref' : 'rowid');
  43. if ($id == "")
  44. {
  45. dol_print_error('','Missing parameter id');
  46. exit();
  47. }
  48. // Security check
  49. $result = restrictedArea($user, 'categorie', $id, '&category');
  50. $object = new Categorie($db);
  51. /*
  52. * Actions
  53. */
  54. // retour a l'affichage des traduction si annulation
  55. if ($cancel == $langs->trans("Cancel"))
  56. {
  57. $action = '';
  58. }
  59. // Validation de l'ajout
  60. if ($action == 'vadd' &&
  61. $cancel != $langs->trans("Cancel") &&
  62. ($user->rights->categorie->creer ))
  63. {
  64. $object->fetch($id);
  65. $current_lang = $langs->getDefaultLang();
  66. // update de l'objet
  67. if ( $_POST["forcelangprod"] == $current_lang )
  68. {
  69. $object->label = $_POST["libelle"];
  70. $object->description = dol_htmlcleanlastbr($_POST["desc"]);
  71. }
  72. else
  73. {
  74. $object->multilangs[$_POST["forcelangprod"]]["label"] = $_POST["libelle"];
  75. $object->multilangs[$_POST["forcelangprod"]]["description"] = dol_htmlcleanlastbr($_POST["desc"]);
  76. }
  77. // sauvegarde en base
  78. if ( $object->setMultiLangs($user) > 0 )
  79. {
  80. $action = '';
  81. }
  82. else
  83. {
  84. $action = 'add';
  85. setEventMessages($object->error, $object->errors, 'errors');
  86. }
  87. }
  88. // Validation de l'edition
  89. if ($action == 'vedit' &&
  90. $cancel != $langs->trans("Cancel") &&
  91. ($user->rights->categorie->creer))
  92. {
  93. $object->fetch($id);
  94. $current_lang = $langs->getDefaultLang();
  95. foreach ( $object->multilangs as $key => $value ) // enregistrement des nouvelles valeurs dans l'objet
  96. {
  97. if ( $key == $current_lang )
  98. {
  99. $object->label = $_POST["libelle-".$key];
  100. $object->description = dol_htmlcleanlastbr($_POST["desc-".$key]);
  101. }
  102. else
  103. {
  104. $object->multilangs[$key]["label"] = $_POST["libelle-".$key];
  105. $object->multilangs[$key]["description"] = dol_htmlcleanlastbr($_POST["desc-".$key]);
  106. }
  107. }
  108. if ( $object->setMultiLangs($user) > 0 )
  109. {
  110. $action = '';
  111. }
  112. else
  113. {
  114. $action = 'edit';
  115. setEventMessages($object->error, $object->errors, 'errors');
  116. }
  117. }
  118. $result = $object->fetch($id,$ref);
  119. /*
  120. * View
  121. */
  122. llxHeader("","",$langs->trans("Translation"));
  123. $form = new Form($db);
  124. $formadmin=new FormAdmin($db);
  125. $formother = new FormOther($db);
  126. if ($type == Categorie::TYPE_PRODUCT) $title=$langs->trans("ProductsCategoryShort");
  127. elseif ($type == Categorie::TYPE_SUPPLIER) $title=$langs->trans("SuppliersCategoryShort");
  128. elseif ($type == Categorie::TYPE_CUSTOMER) $title=$langs->trans("CustomersCategoryShort");
  129. elseif ($type == Categorie::TYPE_MEMBER) $title=$langs->trans("MembersCategoryShort");
  130. elseif ($type == Categorie::TYPE_CONTACT) $title=$langs->trans("ContactCategoriesShort");
  131. elseif ($type == Categorie::TYPE_ACCOUNT) $title=$langs->trans("AccountsCategoriesShort");
  132. elseif ($type == Categorie::TYPE_PROJECT) $title=$langs->trans("ProjectsCategoriesShort");
  133. elseif ($type == Categorie::TYPE_USER) $title=$langs->trans("UsersCategoriesShort");
  134. else $title=$langs->trans("Category");
  135. $head = categories_prepare_head($object,$type);
  136. // Calculate $cnt_trans
  137. $cnt_trans = 0;
  138. if (! empty($object->multilangs))
  139. {
  140. foreach ($object->multilangs as $key => $value)
  141. {
  142. $cnt_trans++;
  143. }
  144. }
  145. dol_fiche_head($head, 'translation', $title, -1, 'category');
  146. $linkback = '<a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("BackToList").'</a>';
  147. $object->ref = $object->label;
  148. $morehtmlref='<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> ';
  149. $ways = $object->print_all_ways(" &gt;&gt; ", '', 1);
  150. foreach ($ways as $way)
  151. {
  152. $morehtmlref.=$way."<br>\n";
  153. }
  154. $morehtmlref.='</div>';
  155. dol_banner_tab($object, 'ref', $linkback, ($user->societe_id?0:1), 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
  156. print '<br>';
  157. print '<div class="fichecenter">';
  158. print '<div class="underbanner clearboth"></div>';
  159. print '<table class="border" width="100%">';
  160. // Description
  161. print '<tr><td class="titlefield notopnoleft">';
  162. print $langs->trans("Description").'</td><td>';
  163. print dol_htmlentitiesbr($object->description);
  164. print '</td></tr>';
  165. // Color
  166. print '<tr><td class="notopnoleft">';
  167. print $langs->trans("Color").'</td><td>';
  168. print $formother->showColor($object->color);
  169. print '</td></tr>';
  170. print '</table>';
  171. print '</div>';
  172. dol_fiche_end();
  173. /* ************************************************************************** */
  174. /* */
  175. /* Barre d'action */
  176. /* */
  177. /* ************************************************************************** */
  178. print "\n<div class=\"tabsAction\">\n";
  179. if ($action == '')
  180. {
  181. if ($user->rights->produit->creer || $user->rights->service->creer)
  182. {
  183. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=add&id='.$object->id.'">'.$langs->trans("Add").'</a>';
  184. if ($cnt_trans > 0) print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&id='.$object->id.'">'.$langs->trans("Update").'</a>';
  185. }
  186. }
  187. print "\n</div>\n";
  188. if ($action == 'edit')
  189. {
  190. //WYSIWYG Editor
  191. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  192. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  193. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  194. print '<input type="hidden" name="action" value="vedit">';
  195. print '<input type="hidden" name="id" value="'.$object->id.'">';
  196. if (! empty($object->multilangs))
  197. {
  198. foreach ($object->multilangs as $key => $value)
  199. {
  200. print "<br><b><u>".$langs->trans('Language_'.$key)." :</u></b><br>";
  201. print '<table class="border" width="100%">';
  202. print '<tr><td class="titlefield fieldrequired">'.$langs->trans('Label').'</td><td><input name="libelle-'.$key.'" size="40" value="'.$object->multilangs[$key]["label"].'"></td></tr>';
  203. print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
  204. $doleditor = new DolEditor("desc-$key", $object->multilangs[$key]["description"], '', 160, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, ROWS_3,'90%');
  205. $doleditor->Create();
  206. print '</td></tr>';
  207. print '</tr>';
  208. print '</table>';
  209. }
  210. }
  211. print '<br>';
  212. print '<div class="center">';
  213. print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
  214. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  215. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  216. print '</div>';
  217. print '</form>';
  218. }
  219. else if ($action != 'add')
  220. {
  221. if ($cnt_trans) print '<div class="underbanner clearboth"></div>';
  222. if (! empty($object->multilangs))
  223. {
  224. foreach ($object->multilangs as $key => $value)
  225. {
  226. $s=picto_from_langcode($key);
  227. print '<table class="border" width="100%">';
  228. 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>';
  229. print '<tr><td class="titlefield">'.$langs->trans('Label').'</td><td>'.$object->multilangs[$key]["label"].'</td></tr>';
  230. print '<tr><td>'.$langs->trans('Description').'</td><td>'.$object->multilangs[$key]["description"].'</td></tr>';
  231. if (! empty($conf->global->CATEGORY_USE_OTHER_FIELD_IN_TRANSLATION))
  232. {
  233. print '<tr><td>'.$langs->trans('Other').' ('.$langs->trans("NotUsed").')</td><td>'.$object->multilangs[$key]["other"].'</td></tr>';
  234. }
  235. print '</table>';
  236. }
  237. }
  238. if (! $cnt_trans && $action != 'add') print '<div class="opacitymedium">'. $langs->trans('NoTranslation').'</div>';
  239. }
  240. /*
  241. * Form to add a new translation
  242. */
  243. if ($action == 'add' && ($user->rights->produit->creer || $user->rights->service->creer))
  244. {
  245. //WYSIWYG Editor
  246. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  247. print '<br>';
  248. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  249. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  250. print '<input type="hidden" name="action" value="vadd">';
  251. print '<input type="hidden" name="id" value="'.$id.'">';
  252. print '<table class="border" width="100%">';
  253. print '<tr><td class="titlefield fieldrequired">'.$langs->trans('Translation').'</td><td>';
  254. print $formadmin->select_language('','forcelangprod',0,$object->multilangs);
  255. print '</td></tr>';
  256. print '<tr><td class="fieldrequired">'.$langs->trans('Label').'</td><td><input name="libelle" size="40"></td></tr>';
  257. print '<tr><td>'.$langs->trans('Description').'</td><td>';
  258. $doleditor = new DolEditor('desc', '', '', 160, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, ROWS_3,'90%');
  259. $doleditor->Create();
  260. print '</td></tr>';
  261. print '</tr>';
  262. print '</table>';
  263. print '<div class="center">';
  264. print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
  265. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  266. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  267. print '</div>';
  268. print '</form>';
  269. print '<br>';
  270. }
  271. // End of page
  272. llxFooter();
  273. $db->close();