traduction.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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. *
  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 de traduction des produits
  25. */
  26. // Load Dolibarr environment
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  32. // Load translation files required by the page
  33. $langs->loadLangs(array('products', 'languages'));
  34. $id = GETPOST('id', 'int');
  35. $ref = GETPOST('ref', 'alpha');
  36. $action = GETPOST('action', 'aZ09');
  37. $cancel = GETPOST('cancel', 'alpha');
  38. // Security check
  39. $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
  40. $fieldtype = (!empty($ref) ? 'ref' : 'rowid');
  41. if ($user->socid) {
  42. $socid = $user->socid;
  43. }
  44. if ($id > 0 || !empty($ref)) {
  45. $object = new Product($db);
  46. $object->fetch($id, $ref);
  47. }
  48. if ($object->id > 0) {
  49. if ($object->type == $object::TYPE_PRODUCT) {
  50. restrictedArea($user, 'produit', $object->id, 'product&product', '', '');
  51. }
  52. if ($object->type == $object::TYPE_SERVICE) {
  53. restrictedArea($user, 'service', $object->id, 'product&product', '', '');
  54. }
  55. } else {
  56. restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
  57. }
  58. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  59. $hookmanager->initHooks(array('producttranslationcard', 'globalcard'));
  60. /*
  61. * Actions
  62. */
  63. $parameters = array('id'=>$id, 'ref'=>$ref);
  64. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  65. if ($reshook < 0) {
  66. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  67. }
  68. if (empty($reshook)) {
  69. // retour a l'affichage des traduction si annulation
  70. if ($cancel == $langs->trans("Cancel")) {
  71. $action = '';
  72. }
  73. if ($action == 'delete' && GETPOST('langtodelete', 'alpha')) {
  74. $object = new Product($db);
  75. $object->fetch($id);
  76. $object->delMultiLangs(GETPOST('langtodelete', 'alpha'), $user);
  77. setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
  78. $action = '';
  79. }
  80. // Add translation
  81. if ($action == 'vadd' && $cancel != $langs->trans("Cancel") && ($user->rights->produit->creer || $user->rights->service->creer)) {
  82. $object = new Product($db);
  83. $object->fetch($id);
  84. $current_lang = $langs->getDefaultLang();
  85. // update de l'objet
  86. if (GETPOST("forcelangprod") == $current_lang) {
  87. $object->label = GETPOST("libelle");
  88. $object->description = dol_htmlcleanlastbr(GETPOST("desc", 'restricthtml'));
  89. $object->other = dol_htmlcleanlastbr(GETPOST("other", 'restricthtml'));
  90. $object->update($object->id, $user);
  91. } else {
  92. $object->multilangs[GETPOST("forcelangprod")]["label"] = GETPOST("libelle");
  93. $object->multilangs[GETPOST("forcelangprod")]["description"] = dol_htmlcleanlastbr(GETPOST("desc", 'restricthtml'));
  94. $object->multilangs[GETPOST("forcelangprod")]["other"] = dol_htmlcleanlastbr(GETPOST("other", 'restricthtml'));
  95. }
  96. // save in database
  97. if (GETPOST("forcelangprod")) {
  98. $result = $object->setMultiLangs($user);
  99. } else {
  100. $object->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Language"));
  101. $result = -1;
  102. }
  103. if ($result > 0) {
  104. $action = '';
  105. } else {
  106. $action = 'add';
  107. setEventMessages($object->error, $object->errors, 'errors');
  108. }
  109. }
  110. // Edit translation
  111. if ($action == 'vedit' && $cancel != $langs->trans("Cancel") && ($user->rights->produit->creer || $user->rights->service->creer)) {
  112. $object = new Product($db);
  113. $object->fetch($id);
  114. $current_lang = $langs->getDefaultLang();
  115. foreach ($object->multilangs as $key => $value) { // enregistrement des nouvelles valeurs dans l'objet
  116. if ($key == $current_lang) {
  117. $object->label = GETPOST("libelle-" . $key);
  118. $object->description = dol_htmlcleanlastbr(GETPOST("desc-" . $key, 'restricthtml'));
  119. $object->other = dol_htmlcleanlastbr(GETPOST("other-" . $key, 'restricthtml'));
  120. } else {
  121. $object->multilangs[$key]["label"] = GETPOST("libelle-" . $key);
  122. $object->multilangs[$key]["description"] = dol_htmlcleanlastbr(GETPOST("desc-" . $key, 'restricthtml'));
  123. $object->multilangs[$key]["other"] = dol_htmlcleanlastbr(GETPOST("other-" . $key, 'restricthtml'));
  124. }
  125. }
  126. $result = $object->setMultiLangs($user);
  127. if ($result > 0) {
  128. $action = '';
  129. } else {
  130. $action = 'edit';
  131. setEventMessages($object->error, $object->errors, 'errors');
  132. }
  133. }
  134. // Delete translation
  135. if ($action == 'vdelete' && $cancel != $langs->trans("Cancel") && ($user->rights->produit->creer || $user->rights->service->creer)) {
  136. $object = new Product($db);
  137. $object->fetch($id);
  138. $langtodelete = GETPOST('langdel', 'alpha');
  139. $result = $object->delMultiLangs($langtodelete, $user);
  140. if ($result > 0) {
  141. $action = '';
  142. } else {
  143. $action = 'edit';
  144. setEventMessages($object->error, $object->errors, 'errors');
  145. }
  146. }
  147. }
  148. $object = new Product($db);
  149. $result = $object->fetch($id, $ref);
  150. /*
  151. * View
  152. */
  153. $title = $langs->trans('ProductServiceCard');
  154. $helpurl = '';
  155. $shortlabel = dol_trunc($object->label, 16);
  156. if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) {
  157. $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('Translation');
  158. $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
  159. }
  160. if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) {
  161. $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('Translation');
  162. $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
  163. }
  164. llxHeader('', $title, $helpurl);
  165. $form = new Form($db);
  166. $formadmin = new FormAdmin($db);
  167. $head = product_prepare_head($object);
  168. $titre = $langs->trans("CardProduct".$object->type);
  169. $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
  170. // Calculate $cnt_trans
  171. $cnt_trans = 0;
  172. if (!empty($object->multilangs)) {
  173. foreach ($object->multilangs as $key => $value) {
  174. $cnt_trans++;
  175. }
  176. }
  177. print dol_get_fiche_head($head, 'translation', $titre, 0, $picto);
  178. $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  179. $shownav = 1;
  180. if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
  181. $shownav = 0;
  182. }
  183. dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref', '', '', '', 0, '', '', 1);
  184. print dol_get_fiche_end();
  185. /*
  186. * Action bar
  187. */
  188. print "\n".'<div class="tabsAction">'."\n";
  189. $parameters = array();
  190. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
  191. if (empty($reshook)) {
  192. if ($action == '') {
  193. if ($user->rights->produit->creer || $user->rights->service->creer) {
  194. print '<a class="butAction" href="' . DOL_URL_ROOT . '/product/traduction.php?action=add&token='.newToken().'&id=' . $object->id . '">' . $langs->trans("Add") . '</a>';
  195. if ($cnt_trans > 0) {
  196. print '<a class="butAction" href="' . DOL_URL_ROOT . '/product/traduction.php?action=edit&token='.newToken().'&id=' . $object->id . '">' . $langs->trans("Modify") . '</a>';
  197. }
  198. }
  199. }
  200. }
  201. print "\n".'</div>'."\n";
  202. if ($action == 'edit') {
  203. //WYSIWYG Editor
  204. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  205. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  206. print '<input type="hidden" name="token" value="'.newToken().'">';
  207. print '<input type="hidden" name="action" value="vedit">';
  208. print '<input type="hidden" name="id" value="'.$object->id.'">';
  209. if (!empty($object->multilangs)) {
  210. $i = 0;
  211. foreach ($object->multilangs as $key => $value) {
  212. $i++;
  213. $s = picto_from_langcode($key);
  214. 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>';
  215. print '<div class="underbanner clearboth"></div>';
  216. print '<table class="border centpercent">';
  217. 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>';
  218. print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
  219. $doleditor = new DolEditor("desc-$key", $object->multilangs[$key]["description"], '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_DETAILS'), ROWS_3, '90%');
  220. $doleditor->Create();
  221. print '</td></tr>';
  222. if (!empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) {
  223. print '<tr><td class="tdtop">'.$langs->trans('Other').' ('.$langs->trans("NotUsed").')</td><td>';
  224. $doleditor = new DolEditor("other-$key", $object->multilangs[$key]["other"], '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_DETAILS'), ROWS_3, '90%');
  225. $doleditor->Create();
  226. }
  227. print '</td></tr>';
  228. print '</table>';
  229. }
  230. }
  231. $parameters = array();
  232. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  233. print '<br>';
  234. print $form->buttonsSaveCancel();
  235. print '</form>';
  236. } elseif ($action != 'add') {
  237. if (!empty($object->multilangs)) {
  238. $i = 0;
  239. foreach ($object->multilangs as $key => $value) {
  240. $i++;
  241. $s = picto_from_langcode($key);
  242. 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>';
  243. print '<div class="fichecenter">';
  244. print '<div class="underbanner clearboth"></div>';
  245. print '<table class="border centpercent">';
  246. print '<tr><td class="titlefieldcreate">'.$langs->trans('Label').'</td><td>'.$object->multilangs[$key]["label"].'</td></tr>';
  247. print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>'.$object->multilangs[$key]["description"].'</td></tr>';
  248. if (!empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) {
  249. print '<tr><td>'.$langs->trans('Other').' ('.$langs->trans("NotUsed").')</td><td>'.$object->multilangs[$key]["other"].'</td></tr>';
  250. }
  251. print '</table>';
  252. print '</div>';
  253. }
  254. }
  255. if (!$cnt_trans && $action != 'add') {
  256. print '<div class="opacitymedium">'.$langs->trans('NoTranslation').'</div>';
  257. }
  258. }
  259. /*
  260. * Form to add a new translation
  261. */
  262. if ($action == 'add' && ($user->rights->produit->creer || $user->rights->service->creer)) {
  263. //WYSIWYG Editor
  264. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  265. print '<br>';
  266. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  267. print '<input type="hidden" name="token" value="'.newToken().'">';
  268. print '<input type="hidden" name="action" value="vadd">';
  269. print '<input type="hidden" name="id" value="'.GETPOST("id", 'int').'">';
  270. print dol_get_fiche_head();
  271. print '<table class="border centpercent">';
  272. print '<tr><td class="tdtop titlefieldcreate fieldrequired">'.$langs->trans('Language').'</td><td>';
  273. print $formadmin->select_language(GETPOST('forcelangprod'), 'forcelangprod', 0, $object->multilangs, 1);
  274. print '</td></tr>';
  275. print '<tr><td class="tdtop fieldrequired">'.$langs->trans('Label').'</td><td><input name="libelle" size="40"></td></tr>';
  276. print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
  277. $doleditor = new DolEditor('desc', '', '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_DETAILS'), ROWS_3, '90%');
  278. $doleditor->Create();
  279. print '</td></tr>';
  280. // Other field (not used)
  281. if (!empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) {
  282. print '<tr><td class="tdtop">'.$langs->trans('Other').' ('.$langs->trans("NotUsed").'</td><td>';
  283. $doleditor = new DolEditor('other', '', '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_DETAILS'), ROWS_3, '90%');
  284. $doleditor->Create();
  285. print '</td></tr>';
  286. }
  287. print '</table>';
  288. $parameters = array();
  289. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  290. print dol_get_fiche_end();
  291. print $form->buttonsSaveCancel();
  292. print '</form>';
  293. print '<br>';
  294. }
  295. // End of page
  296. llxFooter();
  297. $db->close();