PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/product/traduction.php

https://bitbucket.org/speedealing/speedealing
PHP | 290 lines | 191 code | 53 blank | 46 comment | 31 complexity | 9991da8e30c131d53c36bc9159bcdbad MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  3. * Copyright (C) 2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  4. * Copyright (C) 2010-2012 Destailleur Laurent <eldy@users.sourceforge.net>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. * or see http://www.gnu.org/
  19. */
  20. /**
  21. * \file htdocs/product/traduction.php
  22. * \ingroup product
  23. * \brief Page de traduction des produits
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  30. $langs->load("products");
  31. $langs->load("languages");
  32. $id = GETPOST('id', 'int');
  33. $ref = GETPOST('ref', 'alpha');
  34. $action=GETPOST('action','alpha');
  35. $cancel=GETPOST('cancel','alpha');
  36. // Security check
  37. $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
  38. $fieldtype = (! empty($ref) ? 'ref' : 'rowid');
  39. if ($user->societe_id) $socid=$user->societe_id;
  40. $result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype);
  41. /*
  42. * Actions
  43. */
  44. // retour a l'affichage des traduction si annulation
  45. if ($cancel == $langs->trans("Cancel"))
  46. {
  47. $action = '';
  48. }
  49. // Validation de l'ajout
  50. if ($action == 'vadd' &&
  51. $cancel != $langs->trans("Cancel") &&
  52. ($user->rights->produit->creer || $user->rights->service->creer))
  53. {
  54. $product = new Product($db);
  55. $product->fetch($id);
  56. $current_lang = $langs->getDefaultLang();
  57. // update de l'objet
  58. if ( $_POST["forcelangprod"] == $current_lang )
  59. {
  60. $product->label = $_POST["libelle"];
  61. $product->description = dol_htmlcleanlastbr($_POST["desc"]);
  62. $product->note = dol_htmlcleanlastbr($_POST["note"]);
  63. }
  64. else
  65. {
  66. $product->multilangs[$_POST["forcelangprod"]]["label"] = $_POST["libelle"];
  67. $product->multilangs[$_POST["forcelangprod"]]["description"] = dol_htmlcleanlastbr($_POST["desc"]);
  68. $product->multilangs[$_POST["forcelangprod"]]["note"] = dol_htmlcleanlastbr($_POST["note"]);
  69. }
  70. // sauvegarde en base
  71. if ( $product->setMultiLangs() > 0 )
  72. {
  73. $action = '';
  74. }
  75. else
  76. {
  77. $action = 'add';
  78. $mesg = '<div class="error">'.$product->error.'</div>';
  79. }
  80. }
  81. // Validation de l'edition
  82. if ($action == 'vedit' &&
  83. $cancel != $langs->trans("Cancel") &&
  84. ($user->rights->produit->creer || $user->rights->service->creer))
  85. {
  86. $product = new Product($db);
  87. $product->fetch($id);
  88. $current_lang = $langs->getDefaultLang();
  89. foreach ( $product->multilangs as $key => $value ) // enregistrement des nouvelles valeurs dans l'objet
  90. {
  91. if ( $key == $current_lang )
  92. {
  93. $product->label = $_POST["libelle-".$key];
  94. $product->description = dol_htmlcleanlastbr($_POST["desc-".$key]);
  95. $product->note = dol_htmlcleanlastbr($_POST["note-".$key]);
  96. }
  97. else
  98. {
  99. $product->multilangs[$key]["label"] = $_POST["libelle-".$key];
  100. $product->multilangs[$key]["description"] = dol_htmlcleanlastbr($_POST["desc-".$key]);
  101. $product->multilangs[$key]["note"] = dol_htmlcleanlastbr($_POST["note-".$key]);
  102. }
  103. }
  104. if ( $product->setMultiLangs() > 0 )
  105. {
  106. $action = '';
  107. }
  108. else
  109. {
  110. $action = 'edit';
  111. $mesg = '<div class="error">'.$product->error.'</div>';
  112. }
  113. }
  114. $product = new Product($db);
  115. $result = $product->fetch($id,$ref);
  116. /*
  117. * View
  118. */
  119. llxHeader("","",$langs->trans("Translation"));
  120. $form = new Form($db);
  121. $formadmin=new FormAdmin($db);
  122. $head=product_prepare_head($product, $user);
  123. $titre=$langs->trans("CardProduct".$product->type);
  124. $picto=($product->type==1?'service':'product');
  125. dol_fiche_head($head, 'translation', $titre, 0, $picto);
  126. if (! empty($mesg)) {
  127. dol_htmloutput_mesg($mesg);
  128. }
  129. print '<table class="border" width="100%">';
  130. // Reference
  131. print '<tr>';
  132. print '<td width="15%">'.$langs->trans("Ref").'</td><td colspan="2">';
  133. print $form->showrefnav($product,'ref','',1,'ref');
  134. print '</td>';
  135. print '</tr>';
  136. print '</table>';
  137. if ($action == 'edit')
  138. {
  139. //WYSIWYG Editor
  140. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  141. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  142. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  143. print '<input type="hidden" name="action" value="vedit">';
  144. print '<input type="hidden" name="id" value="'.$product->id.'">';
  145. if (! empty($product->multilangs))
  146. {
  147. foreach ($product->multilangs as $key => $value)
  148. {
  149. print "<br><b><u>".$langs->trans('Language_'.$key)." :</u></b><br>";
  150. print '<table class="border" width="100%">';
  151. print '<tr><td valign="top" width="15%" class="fieldrequired">'.$langs->trans('Label').'</td><td><input name="libelle-'.$key.'" size="40" value="'.$product->multilangs[$key]["label"].'"></td></tr>';
  152. print '<tr><td valign="top" width="15%">'.$langs->trans('Description').'</td><td>';
  153. $doleditor = new DolEditor("desc-$key", $product->multilangs[$key]["description"], '', 160, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, 3, 80);
  154. $doleditor->Create();
  155. print '</td></tr>';
  156. print '<tr><td valign="top" width="15%">'.$langs->trans('Note').'</td><td>';
  157. $doleditor = new DolEditor("note-$key", $product->multilangs[$key]["note"], '', 160, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, 3, 80);
  158. $doleditor->Create();
  159. print '</td></tr>';
  160. print '</tr>';
  161. print '</table>';
  162. }
  163. }
  164. print '<br><center>';
  165. print '<input type="submit" class="button" value="'.$langs->trans("Save").'"> &nbsp; &nbsp; ';
  166. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></center>';
  167. print '</form>';
  168. }
  169. else
  170. {
  171. $cnt_trans = 0;
  172. if (! empty($product->multilangs))
  173. {
  174. foreach ($product->multilangs as $key => $value)
  175. {
  176. $cnt_trans++;
  177. $s=picto_from_langcode($key);
  178. print "<br>".($s?$s.' ':'')." <b>".$langs->trans('Language_'.$key).":</b><br>";
  179. print '<table class="border" width="100%">';
  180. print '<tr><td width="15%">'.$langs->trans('Label').'</td><td>'.$product->multilangs[$key]["label"].'</td></tr>';
  181. print '<tr><td width="15%">'.$langs->trans('Description').'</td><td>'.$product->multilangs[$key]["description"].'</td></tr>';
  182. print '<tr><td width="15%">'.$langs->trans('Note').'</td><td>'.$product->multilangs[$key]["note"].'</td></tr>';
  183. print '</table>';
  184. }
  185. }
  186. if (! $cnt_trans) print '<br>'. $langs->trans('NoTranslation');
  187. }
  188. print "</div>\n";
  189. /* ************************************************************************** */
  190. /* */
  191. /* Barre d'action */
  192. /* */
  193. /* ************************************************************************** */
  194. print "\n<div class=\"tabsAction\">\n";
  195. if ($action == '')
  196. if ($user->rights->produit->creer || $user->rights->service->creer)
  197. {
  198. print '<a class="butAction" href="'.DOL_URL_ROOT.'/product/traduction.php?action=add&id='.$product->id.'">'.$langs->trans("Add").'</a>';
  199. print '<a class="butAction" href="'.DOL_URL_ROOT.'/product/traduction.php?action=edit&id='.$product->id.'">'.$langs->trans("Update").'</a>';
  200. }
  201. print "\n</div>\n";
  202. /*
  203. * Form to add a new translation
  204. */
  205. if ($action == 'add' && ($user->rights->produit->creer || $user->rights->service->creer))
  206. {
  207. //WYSIWYG Editor
  208. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  209. print '<br>';
  210. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  211. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  212. print '<input type="hidden" name="action" value="vadd">';
  213. print '<input type="hidden" name="id" value="'.$_GET["id"].'">';
  214. print '<table class="border" width="100%">';
  215. print '<tr><td valign="top" width="15%" class="fieldrequired">'.$langs->trans('Translation').'</td><td>';
  216. print $formadmin->select_language('','forcelangprod',0,$product->multilangs);
  217. print '</td></tr>';
  218. print '<tr><td valign="top" width="15%" class="fieldrequired">'.$langs->trans('Label').'</td><td><input name="libelle" size="40"></td></tr>';
  219. print '<tr><td valign="top" width="15%">'.$langs->trans('Description').'</td><td>';
  220. $doleditor = new DolEditor('desc', '', '', 160, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, 3, 80);
  221. $doleditor->Create();
  222. print '</td></tr>';
  223. print '<tr><td valign="top" width="15%">'.$langs->trans('Note').'</td><td>';
  224. $doleditor = new DolEditor('note', '', '', 160, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, 3, 80);
  225. $doleditor->Create();
  226. print '</td></tr>';
  227. print '</tr>';
  228. print '</table>';
  229. print '<br><center>';
  230. print '<input type="submit" class="button" value="'.$langs->trans("Save").'"> &nbsp; &nbsp; ';
  231. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></center>';
  232. print '</form>';
  233. print '<br>';
  234. }
  235. llxFooter();
  236. $db->close();
  237. ?>