type_translation.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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/adherents/type_translation.php
  23. * \ingroup product
  24. * \brief Member translation page
  25. */
  26. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.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('members', 'languages'));
  33. $id = GETPOST('rowid', 'int');
  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->socid) $socid = $user->socid;
  40. // Security check
  41. $result = restrictedArea($user, 'adherent', $id, 'adherent_type');
  42. /*
  43. * Actions
  44. */
  45. // return to translation display if cancellation
  46. if ($cancel == $langs->trans("Cancel"))
  47. {
  48. $action = '';
  49. }
  50. if ($action == 'delete' && GETPOST('langtodelete', 'alpha'))
  51. {
  52. $object = new AdherentType($db);
  53. $object->fetch($id);
  54. $object->delMultiLangs(GETPOST('langtodelete', 'alpha'), $user);
  55. }
  56. // Add translation
  57. if ($action == 'vadd' && $cancel != $langs->trans("Cancel") && $user->rights->adherent->configurer)
  58. {
  59. $object = new AdherentType($db);
  60. $object->fetch($id);
  61. $current_lang = $langs->getDefaultLang();
  62. // update of object
  63. if ($_POST["forcelangprod"] == $current_lang)
  64. {
  65. $object->label = $_POST["libelle"];
  66. $object->description = dol_htmlcleanlastbr($_POST["desc"]);
  67. $object->other = dol_htmlcleanlastbr($_POST["other"]);
  68. }
  69. else
  70. {
  71. $object->multilangs[$_POST["forcelangprod"]]["label"] = $_POST["libelle"];
  72. $object->multilangs[$_POST["forcelangprod"]]["description"] = dol_htmlcleanlastbr($_POST["desc"]);
  73. $object->multilangs[$_POST["forcelangprod"]]["other"] = dol_htmlcleanlastbr($_POST["other"]);
  74. }
  75. // backup into database
  76. if ($object->setMultiLangs($user) > 0)
  77. {
  78. $action = '';
  79. }
  80. else
  81. {
  82. $action = 'add';
  83. setEventMessages($object->error, $object->errors, 'errors');
  84. }
  85. }
  86. // Edit translation
  87. if ($action == 'vedit' && $cancel != $langs->trans("Cancel") && $user->rights->adherent->configurer)
  88. {
  89. $object = new AdherentType($db);
  90. $object->fetch($id);
  91. $current_lang = $langs->getDefaultLang();
  92. foreach ($object->multilangs as $key => $value) // saving new values in the object
  93. {
  94. if ($key == $current_lang)
  95. {
  96. $object->label = $_POST["libelle-".$key];
  97. $object->description = dol_htmlcleanlastbr($_POST["desc-".$key]);
  98. $object->other = dol_htmlcleanlastbr($_POST["other-".$key]);
  99. }
  100. else
  101. {
  102. $object->multilangs[$key]["label"] = $_POST["libelle-".$key];
  103. $object->multilangs[$key]["description"] = dol_htmlcleanlastbr($_POST["desc-".$key]);
  104. $object->multilangs[$key]["other"] = dol_htmlcleanlastbr($_POST["other-".$key]);
  105. }
  106. }
  107. if ($object->setMultiLangs($user) > 0)
  108. {
  109. $action = '';
  110. }
  111. else
  112. {
  113. $action = 'edit';
  114. setEventMessages($object->error, $object->errors, 'errors');
  115. }
  116. }
  117. // Delete translation
  118. if ($action == 'vdelete' && $cancel != $langs->trans("Cancel") && $user->rights->adherent->configurer)
  119. {
  120. $object = new AdherentType($db);
  121. $object->fetch($id);
  122. $langtodelete = GETPOST('langdel', 'alpha');
  123. if ($object->delMultiLangs($langtodelete, $user) > 0)
  124. {
  125. $action = '';
  126. }
  127. else
  128. {
  129. $action = 'edit';
  130. setEventMessages($object->error, $object->errors, 'errors');
  131. }
  132. }
  133. $object = new AdherentType($db);
  134. $result = $object->fetch($id);
  135. /*
  136. * View
  137. */
  138. $title = $langs->trans('MemberTypeCard');
  139. $helpurl = '';
  140. $shortlabel = dol_trunc($object->label, 16);
  141. $title = $langs->trans('MemberType')." ".$shortlabel." - ".$langs->trans('Translation');
  142. $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
  143. llxHeader('', $title, $helpurl);
  144. $form = new Form($db);
  145. $formadmin = new FormAdmin($db);
  146. $head = member_type_prepare_head($object);
  147. $titre = $langs->trans("MemberType".$object->type);
  148. // Calculate $cnt_trans
  149. $cnt_trans = 0;
  150. if (!empty($object->multilangs))
  151. {
  152. foreach ($object->multilangs as $key => $value)
  153. {
  154. $cnt_trans++;
  155. }
  156. }
  157. dol_fiche_head($head, 'translation', $titre, 0, 'group');
  158. $linkback = '<a href="'.dol_buildpath('/adherents/type.php', 1).'">'.$langs->trans("BackToList").'</a>';
  159. dol_banner_tab($object, 'rowid', $linkback);
  160. dol_fiche_end();
  161. /* ************************************************************************** */
  162. /* */
  163. /* Barre d'action */
  164. /* */
  165. /* ************************************************************************** */
  166. print "\n<div class=\"tabsAction\">\n";
  167. if ($action == '')
  168. {
  169. if ($user->rights->produit->creer || $user->rights->service->creer)
  170. {
  171. print '<a class="butAction" href="'.DOL_URL_ROOT.'/adherents/type_translation.php?action=add&rowid='.$object->id.'">'.$langs->trans("Add").'</a>';
  172. if ($cnt_trans > 0) print '<a class="butAction" href="'.DOL_URL_ROOT.'/adherents/type_translation.php?action=edit&rowid='.$object->id.'">'.$langs->trans("Update").'</a>';
  173. }
  174. }
  175. print "\n</div>\n";
  176. if ($action == 'edit')
  177. {
  178. //WYSIWYG Editor
  179. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  180. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  181. print '<input type="hidden" name="token" value="'.newToken().'">';
  182. print '<input type="hidden" name="action" value="vedit">';
  183. print '<input type="hidden" name="rowid" value="'.$object->id.'">';
  184. if (!empty($object->multilangs))
  185. {
  186. foreach ($object->multilangs as $key => $value)
  187. {
  188. $s = picto_from_langcode($key);
  189. print "<br>".($s ? $s.' ' : '')." <b>".$langs->trans('Language_'.$key).":</b> ".'<a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&action=delete&langtodelete='.$key.'">'.img_delete('', 'class="valigntextbottom"')."</a><br>";
  190. print '<div class="underbanner clearboth"></div>';
  191. print '<table class="border centpercent">';
  192. 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>';
  193. print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
  194. $doleditor = new DolEditor("desc-$key", $object->multilangs[$key]["description"], '', 160, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, ROWS_3, '90%');
  195. $doleditor->Create();
  196. print '</td></tr>';
  197. print '</td></tr>';
  198. print '</table>';
  199. }
  200. }
  201. print '<br>';
  202. print '<div class="center">';
  203. print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
  204. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  205. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  206. print '</div>';
  207. print '</form>';
  208. }
  209. elseif ($action != 'add')
  210. {
  211. if (!empty($object->multilangs))
  212. {
  213. foreach ($object->multilangs as $key => $value)
  214. {
  215. $s = picto_from_langcode($key);
  216. print ($s ? $s.' ' : '')." <b>".$langs->trans('Language_'.$key).":</b> ".'<a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&action=delete&langtodelete='.$key.'">'.img_delete('', 'class="valigntextbottom"').'</a>';
  217. print '<div class="fichecenter">';
  218. print '<div class="underbanner clearboth"></div>';
  219. print '<table class="border centpercent">';
  220. print '<tr><td class="titlefieldcreate">'.$langs->trans('Label').'</td><td>'.$object->multilangs[$key]["label"].'</td></tr>';
  221. print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>'.$object->multilangs[$key]["description"].'</td></tr>';
  222. print '</table>';
  223. print '</div>';
  224. }
  225. }
  226. if (!$cnt_trans && $action != 'add') print '<div class="opacitymedium">'.$langs->trans('NoTranslation').'</div>';
  227. }
  228. /*
  229. * Form to add a new translation
  230. */
  231. if ($action == 'add' && $user->rights->adherent->configurer)
  232. {
  233. //WYSIWYG Editor
  234. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  235. print '<br>';
  236. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  237. print '<input type="hidden" name="token" value="'.newToken().'">';
  238. print '<input type="hidden" name="action" value="vadd">';
  239. print '<input type="hidden" name="rowid" value="'.GETPOST("rowid", 'int').'">';
  240. dol_fiche_head();
  241. print '<table class="border centpercent">';
  242. print '<tr><td class="tdtop titlefieldcreate fieldrequired">'.$langs->trans('Language').'</td><td>';
  243. print $formadmin->select_language('', 'forcelangprod', 0, $object->multilangs, 1);
  244. print '</td></tr>';
  245. print '<tr><td class="tdtop fieldrequired">'.$langs->trans('Label').'</td><td><input name="libelle" size="40"></td></tr>';
  246. print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
  247. $doleditor = new DolEditor('desc', '', '', 160, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, ROWS_3, '90%');
  248. $doleditor->Create();
  249. print '</td></tr>';
  250. print '</table>';
  251. dol_fiche_end();
  252. print '<div class="center">';
  253. print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
  254. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  255. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  256. print '</div>';
  257. print '</form>';
  258. print '<br>';
  259. }
  260. // End of page
  261. llxFooter();
  262. $db->close();