traduction.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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/categories/traduction.php
  23. * \ingroup categories
  24. * \brief Page of translation of categories
  25. */
  26. // Load Dolibarr environment
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  33. // Load translation files required by the page
  34. $langs->loadLangs(array('categories', 'languages'));
  35. $id = GETPOST('id', 'int');
  36. $label = GETPOST('label', 'alpha');
  37. $action = GETPOST('action', 'aZ09');
  38. $cancel = GETPOST('cancel', 'alpha');
  39. if ($id == '' && $label == '') {
  40. dol_print_error('', 'Missing parameter id');
  41. exit();
  42. }
  43. // Security check
  44. $result = restrictedArea($user, 'categorie', $id, '&category');
  45. $object = new Categorie($db);
  46. $result = $object->fetch($id, $label);
  47. if ($result <= 0) {
  48. dol_print_error($db, $object->error); exit;
  49. }
  50. $type = $object->type;
  51. if (is_numeric($type)) {
  52. $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
  53. }
  54. /*
  55. * Actions
  56. */
  57. $error = 0;
  58. // return to translation view if cancelled
  59. if ($cancel == $langs->trans("Cancel")) {
  60. $action = '';
  61. }
  62. // validation of addition
  63. if ($action == 'vadd' &&
  64. $cancel != $langs->trans("Cancel") &&
  65. ($user->rights->categorie->creer)) {
  66. $object->fetch($id);
  67. $current_lang = $langs->getDefaultLang();
  68. // check parameters
  69. $forcelangprod = GETPOST('forcelangprod', 'alpha');
  70. $libelle = GETPOST('libelle', 'alpha');
  71. $desc = GETPOST('desc', 'restricthtml');
  72. if (empty($forcelangprod)) {
  73. $error++;
  74. $object->errors[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Translation'));
  75. }
  76. if (!$error) {
  77. if (empty($libelle)) {
  78. $error++;
  79. $object->errors[] = $langs->trans('Language_'.$forcelangprod).' : '.$langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Label'));
  80. }
  81. if (!$error) {
  82. // update the object
  83. if ($forcelangprod == $current_lang) {
  84. $object->label = $libelle;
  85. $object->description = dol_htmlcleanlastbr($desc);
  86. } else {
  87. $object->multilangs[$forcelangprod]["label"] = $libelle;
  88. $object->multilangs[$forcelangprod]["description"] = dol_htmlcleanlastbr($desc);
  89. }
  90. // save in base / sauvegarde en base
  91. $res = $object->setMultiLangs($user);
  92. if ($res < 0) {
  93. $error++;
  94. }
  95. }
  96. }
  97. if ($error) {
  98. $action = 'add';
  99. setEventMessages($object->error, $object->errors, 'errors');
  100. } else {
  101. $action = '';
  102. }
  103. }
  104. // validation of the edition
  105. if ($action == 'vedit' &&
  106. $cancel != $langs->trans("Cancel") &&
  107. ($user->rights->categorie->creer)) {
  108. $object->fetch($id);
  109. $current_lang = $langs->getDefaultLang();
  110. foreach ($object->multilangs as $key => $value) { // recording of new values in the object
  111. $libelle = GETPOST('libelle-'.$key, 'alpha');
  112. $desc = GETPOST('desc-'.$key);
  113. if (empty($libelle)) {
  114. $error++;
  115. $object->errors[] = $langs->trans('Language_'.$key).' : '.$langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Label'));
  116. }
  117. if ($key == $current_lang) {
  118. $object->label = $libelle;
  119. $object->description = dol_htmlcleanlastbr($desc);
  120. } else {
  121. $object->multilangs[$key]["label"] = $libelle;
  122. $object->multilangs[$key]["description"] = dol_htmlcleanlastbr($desc);
  123. }
  124. }
  125. if (!$error) {
  126. $res = $object->setMultiLangs($user);
  127. if ($res < 0) {
  128. $error++;
  129. }
  130. }
  131. if ($error) {
  132. $action = 'edit';
  133. setEventMessages($object->error, $object->errors, 'errors');
  134. } else {
  135. $action = '';
  136. }
  137. }
  138. /*
  139. * View
  140. */
  141. $form = new Form($db);
  142. $formadmin = new FormAdmin($db);
  143. $formother = new FormOther($db);
  144. llxHeader("", "", $langs->trans("Translation"));
  145. $title = Categorie::$MAP_TYPE_TITLE_AREA[$type];
  146. $head = categories_prepare_head($object, $type);
  147. // Calculate $cnt_trans
  148. $cnt_trans = 0;
  149. if (!empty($object->multilangs)) {
  150. foreach ($object->multilangs as $key => $value) {
  151. $cnt_trans++;
  152. }
  153. }
  154. print dol_get_fiche_head($head, 'translation', $langs->trans($title), -1, 'category');
  155. $backtolist = (GETPOST('backtolist') ? GETPOST('backtolist') : DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.urlencode($type));
  156. $linkback = '<a href="'.dol_sanitizeUrl($backtolist).'">'.$langs->trans("BackToList").'</a>';
  157. $object->next_prev_filter = ' type = '.$object->type;
  158. $object->ref = $object->label;
  159. $morehtmlref = '<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> ';
  160. $ways = $object->print_all_ways(" &gt;&gt; ", '', 1);
  161. foreach ($ways as $way) {
  162. $morehtmlref .= $way."<br>\n";
  163. }
  164. $morehtmlref .= '</div>';
  165. dol_banner_tab($object, 'label', $linkback, ($user->socid ? 0 : 1), 'label', 'label', $morehtmlref, '&type='.$type, 0, '', '', 1);
  166. print '<br>';
  167. print '<div class="fichecenter">';
  168. print '<div class="underbanner clearboth"></div>';
  169. print '<table class="border centpercent tableforfield">';
  170. // Description
  171. print '<tr><td class="titlefield notopnoleft">';
  172. print $langs->trans("Description").'</td><td>';
  173. print dol_htmlentitiesbr($object->description);
  174. print '</td></tr>';
  175. // Color
  176. print '<tr><td class="notopnoleft">';
  177. print $langs->trans("Color").'</td><td>';
  178. print $formother->showColor($object->color);
  179. print '</td></tr>';
  180. print '</table>';
  181. print '</div>';
  182. print dol_get_fiche_end();
  183. /*
  184. * Action bar
  185. */
  186. print "\n<div class=\"tabsAction\">\n";
  187. if ($action == '') {
  188. if ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer')) {
  189. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=add&token='.newToken().'&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&token='.newToken().'&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, getDolGlobalInt('FCKEDITOR_ENABLE_SOCIETE'), ROWS_3, '90%');
  215. $doleditor->Create();
  216. print '</td></tr>';
  217. print '</tr>';
  218. print '</table>';
  219. }
  220. }
  221. print '<br>';
  222. print $form->buttonsSaveCancel();
  223. print '</form>';
  224. } elseif ($action != 'add') {
  225. if ($cnt_trans) {
  226. print '<div class="underbanner clearboth"></div>';
  227. }
  228. if (!empty($object->multilangs)) {
  229. foreach ($object->multilangs as $key => $value) {
  230. $s = picto_from_langcode($key);
  231. print '<table class="border centpercent">';
  232. 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>';
  233. print '<tr><td class="titlefield">'.$langs->trans('Label').'</td><td>'.$object->multilangs[$key]["label"].'</td></tr>';
  234. print '<tr><td>'.$langs->trans('Description').'</td><td>'.$object->multilangs[$key]["description"].'</td></tr>';
  235. if (!empty($conf->global->CATEGORY_USE_OTHER_FIELD_IN_TRANSLATION)) {
  236. print '<tr><td>'.$langs->trans('Other').' ('.$langs->trans("NotUsed").')</td><td>'.$object->multilangs[$key]["other"].'</td></tr>';
  237. }
  238. print '</table>';
  239. }
  240. }
  241. if (!$cnt_trans && $action != 'add') {
  242. print '<div class="opacitymedium">'.$langs->trans('NoTranslation').'</div>';
  243. }
  244. }
  245. /*
  246. * Form to add a new translation
  247. */
  248. if ($action == 'add' && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
  249. //WYSIWYG Editor
  250. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  251. print '<br>';
  252. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  253. print '<input type="hidden" name="token" value="'.newToken().'">';
  254. print '<input type="hidden" name="action" value="vadd">';
  255. print '<input type="hidden" name="id" value="'.$id.'">';
  256. print '<input type="hidden" name="type" value="'.$type.'">';
  257. print '<table class="border centpercent">';
  258. print '<tr><td class="titlefield fieldrequired">'.$langs->trans('Translation').'</td><td>';
  259. print $formadmin->select_language(GETPOST('forcelangprod', 'alpha'), 'forcelangprod', 0, $object->multilangs);
  260. print '</td></tr>';
  261. print '<tr><td class="fieldrequired">'.$langs->trans('Label').'</td>';
  262. print '<td><input name="libelle" class="minwidth200 maxwidth300" value="'.GETPOST('libelle', 'alpha').'"></td></tr>';
  263. print '<tr><td>'.$langs->trans('Description').'</td><td>';
  264. $doleditor = new DolEditor('desc', GETPOST('desc', 'restricthtml'), '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_SOCIETE'), ROWS_3, '90%');
  265. $doleditor->Create();
  266. print '</td></tr>';
  267. print '</tr>';
  268. print '</table>';
  269. print $form->buttonsSaveCancel();
  270. print '</form>';
  271. print '<br>';
  272. }
  273. // End of page
  274. llxFooter();
  275. $db->close();