dolibarr  16.0.5
type_translation.php
Go to the documentation of this file.
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 
28 require '../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
33 
34 // Load translation files required by the page
35 $langs->loadLangs(array('members', 'languages'));
36 
37 $id = GETPOST('rowid', 'int') ? GETPOST('rowid', 'int') : GETPOST('id', 'int');
38 $action = GETPOST('action', 'aZ09');
39 $cancel = GETPOST('cancel', 'alpha');
40 $ref = GETPOST('ref', 'alphanohtml');
41 
42 // Security check
43 $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
44 $fieldtype = (!empty($ref) ? 'ref' : 'rowid');
45 if ($user->socid) {
46  $socid = $user->socid;
47 }
48 // Security check
49 $result = restrictedArea($user, 'adherent', $id, 'adherent_type');
50 
51 
52 /*
53  * Actions
54  */
55 
56 // return to translation display if cancellation
57 if ($cancel == $langs->trans("Cancel")) {
58  $action = '';
59 }
60 
61 if ($action == 'delete' && GETPOST('langtodelete', 'alpha')) {
62  $object = new AdherentType($db);
63  $object->fetch($id);
64  $result = $object->delMultiLangs(GETPOST('langtodelete', 'alpha'), $user);
65  if ($result > 0) {
66  setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
67  header("Location: ".$_SERVER["PHP_SELF"].'?id='.$id);
68  exit;
69  }
70 }
71 
72 // Add translation
73 if ($action == 'vadd' && $cancel != $langs->trans("Cancel") && $user->rights->adherent->configurer) {
74  $object = new AdherentType($db);
75  $object->fetch($id);
76  $current_lang = $langs->getDefaultLang();
77 
78  $forcelangprod = GETPOST("forcelangprod", 'aZ09');
79 
80  // update of object
81  if ($forcelangprod == $current_lang) {
82  $object->label = GETPOST("libelle", 'alphanohtml');
83  $object->description = dol_htmlcleanlastbr(GETPOST("desc", 'restricthtml'));
84  //$object->other = dol_htmlcleanlastbr(GETPOST("other", 'restricthtml'));
85  } else {
86  $object->multilangs[$forcelangprod]["label"] = GETPOST("libelle", 'alphanohtml');
87  $object->multilangs[$forcelangprod]["description"] = dol_htmlcleanlastbr(GETPOST("desc", 'restricthtml'));
88  //$object->multilangs[$forcelangprod]["other"] = dol_htmlcleanlastbr(GETPOST("other", 'restricthtml'));
89  }
90 
91  // backup into database
92  if ($object->setMultiLangs($user) > 0) {
93  $action = '';
94  } else {
95  $action = 'create';
96  setEventMessages($object->error, $object->errors, 'errors');
97  }
98 }
99 
100 // Edit translation
101 if ($action == 'vedit' && $cancel != $langs->trans("Cancel") && $user->rights->adherent->configurer) {
102  $object = new AdherentType($db);
103  $object->fetch($id);
104  $current_lang = $langs->getDefaultLang();
105 
106  foreach ($object->multilangs as $key => $value) { // saving new values in the object
107  if ($key == $current_lang) {
108  $object->label = GETPOST("libelle-".$key, 'alphanohtml');
109  $object->description = dol_htmlcleanlastbr(GETPOST("desc-".$key, 'restricthtml'));
110  $object->other = dol_htmlcleanlastbr(GETPOST("other-".$key, 'restricthtml'));
111  } else {
112  $object->multilangs[$key]["label"] = GETPOST("libelle-".$key, 'alphanohtml');
113  $object->multilangs[$key]["description"] = dol_htmlcleanlastbr(GETPOST("desc-".$key, 'restricthtml'));
114  $object->multilangs[$key]["other"] = dol_htmlcleanlastbr(GETPOST("other-".$key, 'restricthtml'));
115  }
116  }
117 
118  if ($object->setMultiLangs($user) > 0) {
119  $action = '';
120  } else {
121  $action = 'edit';
122  setEventMessages($object->error, $object->errors, 'errors');
123  }
124 }
125 
126 // Delete translation
127 if ($action == 'vdelete' && $cancel != $langs->trans("Cancel") && $user->rights->adherent->configurer) {
128  $object = new AdherentType($db);
129  $object->fetch($id);
130  $langtodelete = GETPOST('langdel', 'alpha');
131 
132 
133  if ($object->delMultiLangs($langtodelete, $user) > 0) {
134  $action = '';
135  } else {
136  $action = 'edit';
137  setEventMessages($object->error, $object->errors, 'errors');
138  }
139 }
140 
141 $object = new AdherentType($db);
142 $result = $object->fetch($id);
143 
144 
145 /*
146  * View
147  */
148 
149 $title = $langs->trans('MemberTypeCard');
150 
151 $help_url = '';
152 
153 $shortlabel = dol_trunc($object->label, 16);
154 
155 $title = $langs->trans('MemberType')." ".$shortlabel." - ".$langs->trans('Translation');
156 
157 $help_url = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios|DE:Modul_Mitglieder';
158 
159 llxHeader('', $title, $help_url);
160 
161 $form = new Form($db);
162 $formadmin = new FormAdmin($db);
163 
164 $head = member_type_prepare_head($object);
165 $titre = $langs->trans("MemberType".$object->id);
166 
167 // Calculate $cnt_trans
168 $cnt_trans = 0;
169 if (!empty($object->multilangs)) {
170  foreach ($object->multilangs as $key => $value) {
171  $cnt_trans++;
172  }
173 }
174 
175 
176 print dol_get_fiche_head($head, 'translation', $titre, 0, 'group');
177 
178 $linkback = '<a href="'.dol_buildpath('/adherents/type.php', 1).'">'.$langs->trans("BackToList").'</a>';
179 
180 dol_banner_tab($object, 'rowid', $linkback);
181 
182 print dol_get_fiche_end();
183 
184 
185 
186 /*
187  * Action bar
188  */
189 print "\n<div class=\"tabsAction\">\n";
190 
191 if ($action == '') {
192  if ($user->rights->produit->creer || $user->rights->service->creer) {
193  print '<a class="butAction" href="'.DOL_URL_ROOT.'/adherents/type_translation.php?action=create&token='.newToken().'&rowid='.$object->id.'">'.$langs->trans("Add").'</a>';
194  if ($cnt_trans > 0) {
195  print '<a class="butAction" href="'.DOL_URL_ROOT.'/adherents/type_translation.php?action=edit&token='.newToken().'&rowid='.$object->id.'">'.$langs->trans("Update").'</a>';
196  }
197  }
198 }
199 
200 print "\n</div>\n";
201 
202 
203 
204 if ($action == 'edit') {
205  //WYSIWYG Editor
206  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
207 
208  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
209  print '<input type="hidden" name="token" value="'.newToken().'">';
210  print '<input type="hidden" name="action" value="vedit">';
211  print '<input type="hidden" name="rowid" value="'.$object->id.'">';
212 
213  if (!empty($object->multilangs)) {
214  foreach ($object->multilangs as $key => $value) {
215  $s = picto_from_langcode($key);
216  print '<br>';
217  print '<div class="inline-block marginbottomonly">';
218  print ($s ? $s.' ' : '').'<b>'.$langs->trans('Language_'.$key).':</b>';
219  print '</div>';
220  print '<div class="inline-block marginbottomonly floatright">';
221  print '<a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&action=delete&token='.newToken().'&langtodelete='.$key.'">'.img_delete('', 'class="valigntextbottom"')."</a><br>";
222  print '</div>';
223 
224  print '<div class="underbanner clearboth"></div>';
225  print '<table class="border centpercent">';
226  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>';
227  print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
228  $doleditor = new DolEditor("desc-$key", $object->multilangs[$key]["description"], '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_PRODUCTDESC'), ROWS_3, '90%');
229  $doleditor->Create();
230  print '</td></tr>';
231  print '</td></tr>';
232  print '</table>';
233  }
234  }
235 
236  print $form->buttonsSaveCancel();
237 
238  print '</form>';
239 } elseif ($action != 'create') {
240  if (!empty($object->multilangs)) {
241  foreach ($object->multilangs as $key => $value) {
242  $s = picto_from_langcode($key);
243  print '<div class="inline-block marginbottomonly">';
244  print ($s ? $s.' ' : '').'<b>'.$langs->trans('Language_'.$key).':</b>';
245  print '</div>';
246  print '<div class="inline-block marginbottomonly floatright">';
247  print '<a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&action=delete&token='.newToken().'&langtodelete='.$key.'">'.img_delete('', 'class="valigntextbottom"').'</a>';
248  print '</div>';
249 
250 
251  print '<div class="fichecenter">';
252  print '<div class="underbanner clearboth"></div>';
253  print '<table class="border centpercent">';
254  print '<tr><td class="titlefieldcreate">'.$langs->trans('Label').'</td><td>'.$object->multilangs[$key]["label"].'</td></tr>';
255  print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>'.$object->multilangs[$key]["description"].'</td></tr>';
256  print '</table>';
257  print '</div>';
258 
259  print '<br>';
260  }
261  }
262  if (!$cnt_trans && $action != 'create') {
263  print '<div class="opacitymedium">'.$langs->trans('NoTranslation').'</div>';
264  }
265 }
266 
267 
268 
269 /*
270  * Form to add a new translation
271  */
272 
273 if ($action == 'create' && $user->rights->adherent->configurer) {
274  //WYSIWYG Editor
275  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
276 
277  print '<br>';
278  print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
279  print '<input type="hidden" name="token" value="'.newToken().'">';
280  print '<input type="hidden" name="action" value="vadd">';
281  print '<input type="hidden" name="rowid" value="'.GETPOST("rowid", 'int').'">';
282 
283  print dol_get_fiche_head();
284 
285  print '<table class="border centpercent">';
286  print '<tr><td class="tdtop titlefieldcreate fieldrequired">'.$langs->trans('Language').'</td><td>';
287  print $formadmin->select_language('', 'forcelangprod', 0, $object->multilangs, 1);
288  print '</td></tr>';
289  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>';
290  print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
291  $doleditor = new DolEditor('desc', '', '', 160, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_PRODUCTDESC'), ROWS_3, '90%');
292  $doleditor->Create();
293  print '</td></tr>';
294 
295  print '</table>';
296 
297  print dol_get_fiche_end();
298 
299  print $form->buttonsSaveCancel();
300 
301  print '</form>';
302 
303  print '<br>';
304 }
305 
306 // End of page
307 llxFooter();
308 $db->close();
AdherentType
Class to manage members type.
Definition: adherent_type.class.php:35
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
dol_trunc
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
Definition: functions.lib.php:3805
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
member_type_prepare_head
member_type_prepare_head(AdherentType $object)
Return array head with list of tabs to view object informations.
Definition: member.lib.php:137
picto_from_langcode
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
Definition: functions.lib.php:8742
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
FormAdmin
Class to generate html code for admin pages.
Definition: html.formadmin.class.php:30
dol_banner_tab
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Definition: functions.lib.php:2046
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
img_delete
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
Definition: functions.lib.php:4429
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_htmlcleanlastbr
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
Definition: functions.lib.php:7036
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:93
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
DolEditor
Class to manage a WYSIWYG editor.
Definition: doleditor.class.php:30