traduction.php 11 KB

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