type_translation.php 10 KB

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