dolibarr 21.0.0-alpha
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 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 * or see https://www.gnu.org/
21 */
22
29// Load Dolibarr environment
30require '../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
35
36// Load translation files required by the page
37$langs->loadLangs(array('members', 'languages'));
38
39$id = GETPOSTINT('rowid') ? GETPOSTINT('rowid') : GETPOSTINT('id');
40$action = GETPOST('action', 'aZ09');
41$cancel = GETPOST('cancel', 'alpha');
42$ref = GETPOST('ref', 'alphanohtml');
43
44// Security check
45$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
46$fieldtype = (!empty($ref) ? 'ref' : 'rowid');
47if ($user->socid) {
48 $socid = $user->socid;
49}
50// Security check
51$result = restrictedArea($user, 'adherent', $id, 'adherent_type');
52
53
54/*
55 * Actions
56 */
57
58// return to translation display if cancellation
59if ($cancel == $langs->trans("Cancel")) {
60 $action = '';
61}
62
63if ($action == 'delete' && GETPOST('langtodelete', 'alpha') && $user->hasRight('adherent', 'configurer')) {
64 $object = new AdherentType($db);
65 $object->fetch($id);
66 $result = $object->delMultiLangs(GETPOST('langtodelete', 'alpha'), $user);
67 if ($result > 0) {
68 setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
69 header("Location: ".$_SERVER["PHP_SELF"].'?id='.$id);
70 exit;
71 }
72}
73
74// Add translation
75if ($action == 'vadd' && $cancel != $langs->trans("Cancel") && $user->hasRight('adherent', 'configurer')) {
76 $object = new AdherentType($db);
77 $object->fetch($id);
78 $current_lang = $langs->getDefaultLang();
79
80 $forcelangprod = GETPOST("forcelangprod", 'aZ09');
81
82 // update of object
83 if ($forcelangprod == $current_lang) {
84 $object->label = GETPOST("libelle", 'alphanohtml');
85 $object->description = dol_htmlcleanlastbr(GETPOST("desc", 'restricthtml'));
86 //$object->other = dol_htmlcleanlastbr(GETPOST("other", 'restricthtml'));
87 } else {
88 $object->multilangs[$forcelangprod]["label"] = GETPOST("libelle", 'alphanohtml');
89 $object->multilangs[$forcelangprod]["description"] = dol_htmlcleanlastbr(GETPOST("desc", 'restricthtml'));
90 //$object->multilangs[$forcelangprod]["other"] = dol_htmlcleanlastbr(GETPOST("other", 'restricthtml'));
91 }
92
93 // backup into database
94 if ($object->setMultiLangs($user) > 0) {
95 $action = '';
96 } else {
97 $action = 'create';
98 setEventMessages($object->error, $object->errors, 'errors');
99 }
100}
101
102// Edit translation
103if ($action == 'vedit' && $cancel != $langs->trans("Cancel") && $user->hasRight('adherent', 'configurer')) {
104 $object = new AdherentType($db);
105 $object->fetch($id);
106 $current_lang = $langs->getDefaultLang();
107
108 foreach ($object->multilangs as $key => $value) { // saving new values in the object
109 if ($key == $current_lang) {
110 $object->label = GETPOST("libelle-".$key, 'alphanohtml');
111 $object->description = dol_htmlcleanlastbr(GETPOST("desc-".$key, 'restricthtml'));
112 $object->other = dol_htmlcleanlastbr(GETPOST("other-".$key, 'restricthtml'));
113 } else {
114 $object->multilangs[$key]["label"] = GETPOST("libelle-".$key, 'alphanohtml');
115 $object->multilangs[$key]["description"] = dol_htmlcleanlastbr(GETPOST("desc-".$key, 'restricthtml'));
116 $object->multilangs[$key]["other"] = dol_htmlcleanlastbr(GETPOST("other-".$key, 'restricthtml'));
117 }
118 }
119
120 if ($object->setMultiLangs($user) > 0) {
121 $action = '';
122 } else {
123 $action = 'edit';
124 setEventMessages($object->error, $object->errors, 'errors');
125 }
126}
127
128// Delete translation
129if ($action == 'vdelete' && $cancel != $langs->trans("Cancel") && $user->hasRight('adherent', 'configurer')) {
130 $object = new AdherentType($db);
131 $object->fetch($id);
132 $langtodelete = GETPOST('langdel', 'alpha');
133
134
135 if ($object->delMultiLangs($langtodelete, $user) > 0) {
136 $action = '';
137 } else {
138 $action = 'edit';
139 setEventMessages($object->error, $object->errors, 'errors');
140 }
141}
142
143$object = new AdherentType($db);
144$result = $object->fetch($id);
145
146
147/*
148 * View
149 */
150
151$title = $langs->trans('MemberTypeCard');
152
153$help_url = '';
154
155$shortlabel = dol_trunc($object->label, 16);
156
157$title = $langs->trans('MemberType')." ".$shortlabel." - ".$langs->trans('Translation');
158$help_url = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios|DE:Modul_Mitglieder';
159
160llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-member page-type_translation');
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;
170if (!empty($object->multilangs)) {
171 foreach ($object->multilangs as $key => $value) {
172 $cnt_trans++;
173 }
174}
175
176
177print 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
181dol_banner_tab($object, 'rowid', $linkback);
182
183print dol_get_fiche_end();
184
185
186
187/*
188 * Action bar
189 */
190print "\n<div class=\"tabsAction\">\n";
191
192if ($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
201print "\n</div>\n";
202
203
204
205if ($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, isModEnabled('fckeditor') && 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
274if ($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="'.GETPOSTINT("rowid").'">';
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, isModEnabled('fckeditor'), 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
308llxFooter();
309$db->close();
$id
Definition account.php:39
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
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.
llxFooter()
Footer empty.
Definition document.php:107
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return a 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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
member_type_prepare_head(AdherentType $object)
Return array head with list of tabs to view object information.
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.