traduction.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. $backtolist = (GETPOST('backtolist') ? GETPOST('backtolist') : DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.urlencode($type));
  155. $linkback = '<a href="'.dol_sanitizeUrl($backtolist).'">'.$langs->trans("BackToList").'</a>';
  156. $object->next_prev_filter = ' type = '.$object->type;
  157. $object->ref = $object->label;
  158. $morehtmlref = '<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> ';
  159. $ways = $object->print_all_ways(" &gt;&gt; ", '', 1);
  160. foreach ($ways as $way) {
  161. $morehtmlref .= $way."<br>\n";
  162. }
  163. $morehtmlref .= '</div>';
  164. dol_banner_tab($object, 'label', $linkback, ($user->socid ? 0 : 1), 'label', 'label', $morehtmlref, '&type='.$type, 0, '', '', 1);
  165. print '<br>';
  166. print '<div class="fichecenter">';
  167. print '<div class="underbanner clearboth"></div>';
  168. print '<table class="border centpercent tableforfield">';
  169. // Description
  170. print '<tr><td class="titlefield notopnoleft">';
  171. print $langs->trans("Description").'</td><td>';
  172. print dol_htmlentitiesbr($object->description);
  173. print '</td></tr>';
  174. // Color
  175. print '<tr><td class="notopnoleft">';
  176. print $langs->trans("Color").'</td><td>';
  177. print $formother->showColor($object->color);
  178. print '</td></tr>';
  179. print '</table>';
  180. print '</div>';
  181. print dol_get_fiche_end();
  182. /*
  183. * Action bar
  184. */
  185. print "\n<div class=\"tabsAction\">\n";
  186. if ($action == '') {
  187. if ($user->rights->produit->creer || $user->rights->service->creer) {
  188. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=add&token='.newToken().'&id='.$object->id.'&type='.$type.'">'.$langs->trans('Add').'</a>';
  189. if ($cnt_trans > 0) {
  190. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&token='.newToken().'&id='.$object->id.'&type='.$type.'">'.$langs->trans('Update').'</a>';
  191. }
  192. }
  193. }
  194. print "\n</div>\n";
  195. if ($action == 'edit') {
  196. //WYSIWYG Editor
  197. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  198. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  199. print '<input type="hidden" name="token" value="'.newToken().'">';
  200. print '<input type="hidden" name="action" value="vedit">';
  201. print '<input type="hidden" name="id" value="'.$object->id.'">';
  202. print '<input type="hidden" name="type" value="'.$type.'">';
  203. if (!empty($object->multilangs)) {
  204. foreach ($object->multilangs as $key => $value) {
  205. print "<br><b><u>".$langs->trans('Language_'.$key)." :</u></b><br>";
  206. print '<table class="border centpercent">';
  207. // Label
  208. $libelle = (GETPOST('libelle-'.$key, 'alpha') ? GETPOST('libelle-'.$key, 'alpha') : $object->multilangs[$key]['label']);
  209. print '<tr><td class="titlefield fieldrequired">'.$langs->trans('Label').'</td><td><input name="libelle-'.$key.'" size="40" value="'.$libelle.'"></td></tr>';
  210. // Desc
  211. $desc = (GETPOST('desc-'.$key) ? GETPOST('desc-'.$key) : $object->multilangs[$key]['description']);
  212. print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
  213. $doleditor = new DolEditor("desc-$key", $desc, '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_PRODUCTDESC'), ROWS_3, '90%');
  214. $doleditor->Create();
  215. print '</td></tr>';
  216. print '</tr>';
  217. print '</table>';
  218. }
  219. }
  220. print '<br>';
  221. print $form->buttonsSaveCancel();
  222. print '</form>';
  223. } elseif ($action != 'add') {
  224. if ($cnt_trans) {
  225. print '<div class="underbanner clearboth"></div>';
  226. }
  227. if (!empty($object->multilangs)) {
  228. foreach ($object->multilangs as $key => $value) {
  229. $s = picto_from_langcode($key);
  230. print '<table class="border centpercent">';
  231. 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>';
  232. print '<tr><td class="titlefield">'.$langs->trans('Label').'</td><td>'.$object->multilangs[$key]["label"].'</td></tr>';
  233. print '<tr><td>'.$langs->trans('Description').'</td><td>'.$object->multilangs[$key]["description"].'</td></tr>';
  234. if (!empty($conf->global->CATEGORY_USE_OTHER_FIELD_IN_TRANSLATION)) {
  235. print '<tr><td>'.$langs->trans('Other').' ('.$langs->trans("NotUsed").')</td><td>'.$object->multilangs[$key]["other"].'</td></tr>';
  236. }
  237. print '</table>';
  238. }
  239. }
  240. if (!$cnt_trans && $action != 'add') {
  241. print '<div class="opacitymedium">'.$langs->trans('NoTranslation').'</div>';
  242. }
  243. }
  244. /*
  245. * Form to add a new translation
  246. */
  247. if ($action == 'add' && ($user->rights->produit->creer || $user->rights->service->creer)) {
  248. //WYSIWYG Editor
  249. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  250. print '<br>';
  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="vadd">';
  254. print '<input type="hidden" name="id" value="'.$id.'">';
  255. print '<input type="hidden" name="type" value="'.$type.'">';
  256. print '<table class="border centpercent">';
  257. print '<tr><td class="titlefield fieldrequired">'.$langs->trans('Translation').'</td><td>';
  258. print $formadmin->select_language(GETPOST('forcelangprod', 'alpha'), 'forcelangprod', 0, $object->multilangs);
  259. print '</td></tr>';
  260. print '<tr><td class="fieldrequired">'.$langs->trans('Label').'</td>';
  261. print '<td><input name="libelle" class="minwidth200 maxwidth300" value="'.GETPOST('libelle', 'alpha').'"></td></tr>';
  262. print '<tr><td>'.$langs->trans('Description').'</td><td>';
  263. $doleditor = new DolEditor('desc', GETPOST('desc', 'restricthtml'), '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_PRODUCTDESC'), ROWS_3, '90%');
  264. $doleditor->Create();
  265. print '</td></tr>';
  266. print '</tr>';
  267. print '</table>';
  268. print $form->buttonsSaveCancel();
  269. print '</form>';
  270. print '<br>';
  271. }
  272. // End of page
  273. llxFooter();
  274. $db->close();