traduction.php 12 KB

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