traduction.php 12 KB

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