traduction.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <?php
  2. /* Copyright (C) 2005-2018 Regis Houssin <regis.houssin@inodbox.com>
  3. * Copyright (C) 2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  4. * Copyright (C) 2010-2012 Destailleur Laurent <eldy@users.sourceforge.net>
  5. * Copyright (C) 2014 Henry Florian <florian.henry@open-concept.pro>
  6. * Copyright (C) 2023 Benjamin Falière <benjamin.faliere@altairis.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. * or see https://www.gnu.org/
  21. */
  22. /**
  23. * \file htdocs/product/traduction.php
  24. * \ingroup product
  25. * \brief Page de traduction des produits
  26. */
  27. // Load Dolibarr environment
  28. require '../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  33. // Load translation files required by the page
  34. $langs->loadLangs(array('products', 'languages'));
  35. $id = GETPOST('id', 'int');
  36. $ref = GETPOST('ref', 'alpha');
  37. $action = GETPOST('action', 'aZ09');
  38. $cancel = GETPOST('cancel', 'alpha');
  39. // Security check
  40. $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
  41. $fieldtype = (!empty($ref) ? 'ref' : 'rowid');
  42. if ($user->socid) {
  43. $socid = $user->socid;
  44. }
  45. if ($id > 0 || !empty($ref)) {
  46. $object = new Product($db);
  47. $object->fetch($id, $ref);
  48. }
  49. if ($object->id > 0) {
  50. if ($object->type == $object::TYPE_PRODUCT) {
  51. restrictedArea($user, 'produit', $object->id, 'product&product', '', '');
  52. }
  53. if ($object->type == $object::TYPE_SERVICE) {
  54. restrictedArea($user, 'service', $object->id, 'product&product', '', '');
  55. }
  56. } else {
  57. restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
  58. }
  59. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  60. $hookmanager->initHooks(array('producttranslationcard', 'globalcard'));
  61. /*
  62. * Actions
  63. */
  64. $parameters = array('id'=>$id, 'ref'=>$ref);
  65. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  66. if ($reshook < 0) {
  67. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  68. }
  69. if (empty($reshook)) {
  70. // retour a l'affichage des traduction si annulation
  71. if ($cancel == $langs->trans("Cancel")) {
  72. $action = '';
  73. }
  74. if ($action == 'delete' && GETPOST('langtodelete', 'alpha')) {
  75. $object = new Product($db);
  76. $object->fetch($id);
  77. $object->delMultiLangs(GETPOST('langtodelete', 'alpha'), $user);
  78. setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
  79. $action = '';
  80. }
  81. // Add translation
  82. if ($action == 'vadd' && $cancel != $langs->trans("Cancel") && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
  83. $object = new Product($db);
  84. $object->fetch($id);
  85. $current_lang = $langs->getDefaultLang();
  86. // update de l'objet
  87. if (GETPOST("forcelangprod") == $current_lang) {
  88. $object->label = GETPOST("libelle");
  89. $object->description = dol_htmlcleanlastbr(GETPOST("desc", 'restricthtml'));
  90. $object->other = dol_htmlcleanlastbr(GETPOST("other", 'restricthtml'));
  91. $object->update($object->id, $user);
  92. } else {
  93. $object->multilangs[GETPOST("forcelangprod")]["label"] = GETPOST("libelle");
  94. $object->multilangs[GETPOST("forcelangprod")]["description"] = dol_htmlcleanlastbr(GETPOST("desc", 'restricthtml'));
  95. $object->multilangs[GETPOST("forcelangprod")]["other"] = dol_htmlcleanlastbr(GETPOST("other", 'restricthtml'));
  96. }
  97. // save in database
  98. if (GETPOST("forcelangprod")) {
  99. $result = $object->setMultiLangs($user);
  100. } else {
  101. $object->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Language"));
  102. $result = -1;
  103. }
  104. if ($result > 0) {
  105. $action = '';
  106. } else {
  107. $action = 'add';
  108. setEventMessages($object->error, $object->errors, 'errors');
  109. }
  110. }
  111. // Edit translation
  112. if ($action == 'vedit' && $cancel != $langs->trans("Cancel") && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
  113. $object = new Product($db);
  114. $object->fetch($id);
  115. $current_lang = $langs->getDefaultLang();
  116. foreach ($object->multilangs as $key => $value) { // enregistrement des nouvelles valeurs dans l'objet
  117. if ($key == $current_lang) {
  118. $object->label = GETPOST("libelle-" . $key);
  119. $object->description = dol_htmlcleanlastbr(GETPOST("desc-" . $key, 'restricthtml'));
  120. $object->other = dol_htmlcleanlastbr(GETPOST("other-" . $key, 'restricthtml'));
  121. $object->update($object->id, $user);
  122. } else {
  123. $object->multilangs[$key]["label"] = GETPOST("libelle-" . $key);
  124. $object->multilangs[$key]["description"] = dol_htmlcleanlastbr(GETPOST("desc-" . $key, 'restricthtml'));
  125. $object->multilangs[$key]["other"] = dol_htmlcleanlastbr(GETPOST("other-" . $key, 'restricthtml'));
  126. }
  127. }
  128. $result = $object->setMultiLangs($user);
  129. if ($result > 0) {
  130. $action = '';
  131. } else {
  132. $action = 'edit';
  133. setEventMessages($object->error, $object->errors, 'errors');
  134. }
  135. }
  136. // Delete translation
  137. if ($action == 'vdelete' && $cancel != $langs->trans("Cancel") && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
  138. $object = new Product($db);
  139. $object->fetch($id);
  140. $langtodelete = GETPOST('langdel', 'alpha');
  141. $result = $object->delMultiLangs($langtodelete, $user);
  142. if ($result > 0) {
  143. $action = '';
  144. } else {
  145. $action = 'edit';
  146. setEventMessages($object->error, $object->errors, 'errors');
  147. }
  148. }
  149. }
  150. $object = new Product($db);
  151. $result = $object->fetch($id, $ref);
  152. /*
  153. * View
  154. */
  155. $title = $langs->trans('ProductServiceCard');
  156. $helpurl = '';
  157. $shortlabel = dol_trunc($object->label, 16);
  158. if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) {
  159. $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('Translation');
  160. $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
  161. }
  162. if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) {
  163. $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('Translation');
  164. $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
  165. }
  166. llxHeader('', $title, $helpurl);
  167. $form = new Form($db);
  168. $formadmin = new FormAdmin($db);
  169. $head = product_prepare_head($object);
  170. $titre = $langs->trans("CardProduct".$object->type);
  171. $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
  172. // Calculate $cnt_trans
  173. $cnt_trans = 0;
  174. if (!empty($object->multilangs)) {
  175. foreach ($object->multilangs as $key => $value) {
  176. $cnt_trans++;
  177. }
  178. }
  179. print dol_get_fiche_head($head, 'translation', $titre, 0, $picto);
  180. $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  181. $shownav = 1;
  182. if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
  183. $shownav = 0;
  184. }
  185. dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref', '', '', '', 0, '', '', 1);
  186. print dol_get_fiche_end();
  187. /*
  188. * Action bar
  189. */
  190. print "\n".'<div class="tabsAction">'."\n";
  191. $parameters = array();
  192. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
  193. if (empty($reshook)) {
  194. if ($action == '') {
  195. if ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer')) {
  196. print '<a class="butAction" href="' . DOL_URL_ROOT . '/product/traduction.php?action=add&token='.newToken().'&id=' . $object->id . '">' . $langs->trans("Add") . '</a>';
  197. if ($cnt_trans > 0) {
  198. print '<a class="butAction" href="' . DOL_URL_ROOT . '/product/traduction.php?action=edit&token='.newToken().'&id=' . $object->id . '">' . $langs->trans("Modify") . '</a>';
  199. }
  200. }
  201. }
  202. }
  203. print "\n".'</div>'."\n";
  204. if ($action == 'edit') {
  205. //WYSIWYG Editor
  206. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  207. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  208. print '<input type="hidden" name="token" value="'.newToken().'">';
  209. print '<input type="hidden" name="action" value="vedit">';
  210. print '<input type="hidden" name="id" value="'.$object->id.'">';
  211. if (!empty($object->multilangs)) {
  212. $i = 0;
  213. foreach ($object->multilangs as $key => $value) {
  214. $i++;
  215. $s = picto_from_langcode($key);
  216. print ($i > 1 ? "<br>" : "").($s ? $s.' ' : '').' <div class="inline-block margintop marginbottomonly"><b>'.$langs->trans('Language_'.$key).'</b></div><div class="inline-block floatright"><a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'&langtodelete='.$key.'">'.img_delete('', 'class="valigntextbottom marginrightonly"').'</a></div>';
  217. print '<div class="underbanner clearboth"></div>';
  218. print '<table class="border centpercent">';
  219. print '<tr><td class="tdtop titlefieldcreate fieldrequired">'.$langs->trans('Label').'</td><td><input name="libelle-'.$key.'" size="40" value="'.dol_escape_htmltag($object->multilangs[$key]["label"]).'"></td></tr>';
  220. print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
  221. $doleditor = new DolEditor("desc-$key", $object->multilangs[$key]["description"], '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_DETAILS'), ROWS_3, '90%');
  222. $doleditor->Create();
  223. print '</td></tr>';
  224. if (!empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) {
  225. print '<tr><td class="tdtop">'.$langs->trans('Other').' ('.$langs->trans("NotUsed").')</td><td>';
  226. $doleditor = new DolEditor("other-$key", $object->multilangs[$key]["other"], '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_DETAILS'), ROWS_3, '90%');
  227. $doleditor->Create();
  228. }
  229. print '</td></tr>';
  230. print '</table>';
  231. }
  232. }
  233. $parameters = array();
  234. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  235. print '<br>';
  236. print $form->buttonsSaveCancel();
  237. print '</form>';
  238. } elseif ($action != 'add') {
  239. if (!empty($object->multilangs)) {
  240. $i = 0;
  241. foreach ($object->multilangs as $key => $value) {
  242. $i++;
  243. $s = picto_from_langcode($key);
  244. print ($i > 1 ? "<br>" : "").($s ? $s.' ' : '').' <div class="inline-block marginbottomonly"><b>'.$langs->trans('Language_'.$key).'</b></div><div class="inline-block floatright"><a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'&langtodelete='.$key.'">'.img_delete('', 'class="valigntextbottom marginrightonly"').'</a></div>';
  245. print '<div class="fichecenter">';
  246. print '<div class="underbanner clearboth"></div>';
  247. print '<table class="border centpercent">';
  248. print '<tr><td class="titlefieldcreate">'.$langs->trans('Label').'</td><td>'.$object->multilangs[$key]["label"].'</td></tr>';
  249. print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>'.$object->multilangs[$key]["description"].'</td></tr>';
  250. if (!empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) {
  251. print '<tr><td>'.$langs->trans('Other').' ('.$langs->trans("NotUsed").')</td><td>'.$object->multilangs[$key]["other"].'</td></tr>';
  252. }
  253. print '</table>';
  254. print '</div>';
  255. }
  256. }
  257. if (!$cnt_trans && $action != 'add') {
  258. print '<div class="opacitymedium">'.$langs->trans('NoTranslation').'</div>';
  259. }
  260. }
  261. /*
  262. * Form to add a new translation
  263. */
  264. if ($action == 'add' && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
  265. //WYSIWYG Editor
  266. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  267. print '<br>';
  268. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  269. print '<input type="hidden" name="token" value="'.newToken().'">';
  270. print '<input type="hidden" name="action" value="vadd">';
  271. print '<input type="hidden" name="id" value="'.GETPOST("id", 'int').'">';
  272. print dol_get_fiche_head();
  273. print '<table class="border centpercent">';
  274. print '<tr><td class="tdtop titlefieldcreate fieldrequired">'.$langs->trans('Language').'</td><td>';
  275. print $formadmin->select_language(GETPOST('forcelangprod'), 'forcelangprod', 0, $object->multilangs, 1);
  276. print '</td></tr>';
  277. print '<tr><td class="tdtop fieldrequired">'.$langs->trans('Label').'</td><td><input name="libelle" size="40"></td></tr>';
  278. print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
  279. $doleditor = new DolEditor('desc', '', '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_DETAILS'), ROWS_3, '90%');
  280. $doleditor->Create();
  281. print '</td></tr>';
  282. // Other field (not used)
  283. if (!empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) {
  284. print '<tr><td class="tdtop">'.$langs->trans('Other').' ('.$langs->trans("NotUsed").'</td><td>';
  285. $doleditor = new DolEditor('other', '', '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_DETAILS'), ROWS_3, '90%');
  286. $doleditor->Create();
  287. print '</td></tr>';
  288. }
  289. print '</table>';
  290. $parameters = array();
  291. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  292. print dol_get_fiche_end();
  293. print $form->buttonsSaveCancel();
  294. print '</form>';
  295. print '<br>';
  296. }
  297. // End of page
  298. llxFooter();
  299. $db->close();