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