traduction.php 13 KB

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