type_translation.php 10 KB

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