dolibarr 21.0.0-beta
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 * or see https://www.gnu.org/
22 */
23
30// Load Dolibarr environment
31require '../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
36
45// Load translation files required by the page
46$langs->loadLangs(array('members', 'languages'));
47
48$id = GETPOSTINT('rowid') ? GETPOSTINT('rowid') : GETPOSTINT('id');
49$action = GETPOST('action', 'aZ09');
50$cancel = GETPOST('cancel', 'alpha');
51$ref = GETPOST('ref', 'alphanohtml');
52
53// Security check
54$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
55$fieldtype = (!empty($ref) ? 'ref' : 'rowid');
56if ($user->socid) {
57 $socid = $user->socid;
58}
59// Security check
60$result = restrictedArea($user, 'adherent', $id, 'adherent_type');
61
62
63/*
64 * Actions
65 */
66
67// return to translation display if cancellation
68if ($cancel == $langs->trans("Cancel")) {
69 $action = '';
70}
71
72if ($action == 'delete' && GETPOST('langtodelete', 'alpha') && $user->hasRight('adherent', 'configurer')) {
73 $object = new AdherentType($db);
74 $object->fetch($id);
75 $result = $object->delMultiLangs(GETPOST('langtodelete', 'alpha'), $user);
76 if ($result > 0) {
77 setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
78 header("Location: ".$_SERVER["PHP_SELF"].'?id='.$id);
79 exit;
80 }
81}
82
83// Add translation
84if ($action == 'vadd' && $cancel != $langs->trans("Cancel") && $user->hasRight('adherent', 'configurer')) {
85 $object = new AdherentType($db);
86 $object->fetch($id);
87 $current_lang = $langs->getDefaultLang();
88
89 $forcelangprod = GETPOST("forcelangprod", 'aZ09');
90
91 // update of object
92 if ($forcelangprod == $current_lang) {
93 $object->label = GETPOST("libelle", 'alphanohtml');
94 $object->description = dol_htmlcleanlastbr(GETPOST("desc", 'restricthtml'));
95 //$object->other = dol_htmlcleanlastbr(GETPOST("other", 'restricthtml'));
96 } else {
97 $object->multilangs[$forcelangprod]["label"] = GETPOST("libelle", 'alphanohtml');
98 $object->multilangs[$forcelangprod]["description"] = dol_htmlcleanlastbr(GETPOST("desc", 'restricthtml'));
99 //$object->multilangs[$forcelangprod]["other"] = dol_htmlcleanlastbr(GETPOST("other", 'restricthtml'));
100 }
101
102 // backup into database
103 if ($object->setMultiLangs($user) > 0) {
104 $action = '';
105 } else {
106 $action = 'create';
107 setEventMessages($object->error, $object->errors, 'errors');
108 }
109}
110
111// Edit translation
112if ($action == 'vedit' && $cancel != $langs->trans("Cancel") && $user->hasRight('adherent', 'configurer')) {
113 $object = new AdherentType($db);
114 $object->fetch($id);
115 $current_lang = $langs->getDefaultLang();
116
117 foreach ($object->multilangs as $key => $value) { // saving new values in the object
118 if ($key == $current_lang) {
119 $object->label = GETPOST("libelle-".$key, 'alphanohtml');
120 $object->description = dol_htmlcleanlastbr(GETPOST("desc-".$key, 'restricthtml'));
121 $object->other = dol_htmlcleanlastbr(GETPOST("other-".$key, 'restricthtml'));
122 } else {
123 $object->multilangs[$key]["label"] = GETPOST("libelle-".$key, 'alphanohtml');
124 $object->multilangs[$key]["description"] = dol_htmlcleanlastbr(GETPOST("desc-".$key, 'restricthtml'));
125 $object->multilangs[$key]["other"] = dol_htmlcleanlastbr(GETPOST("other-".$key, 'restricthtml'));
126 }
127 }
128
129 if ($object->setMultiLangs($user) > 0) {
130 $action = '';
131 } else {
132 $action = 'edit';
133 setEventMessages($object->error, $object->errors, 'errors');
134 }
135}
136
137// Delete translation
138if ($action == 'vdelete' && $cancel != $langs->trans("Cancel") && $user->hasRight('adherent', 'configurer')) {
139 $object = new AdherentType($db);
140 $object->fetch($id);
141 $langtodelete = GETPOST('langdel', 'alpha');
142
143
144 if ($object->delMultiLangs($langtodelete, $user) > 0) {
145 $action = '';
146 } else {
147 $action = 'edit';
148 setEventMessages($object->error, $object->errors, 'errors');
149 }
150}
151
152$object = new AdherentType($db);
153$result = $object->fetch($id);
154
155
156/*
157 * View
158 */
159
160$title = $langs->trans('MemberTypeCard');
161
162$help_url = '';
163
164$shortlabel = dol_trunc($object->label, 16);
165
166$title = $langs->trans('MemberType')." ".$shortlabel." - ".$langs->trans('Translation');
167$help_url = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios|DE:Modul_Mitglieder';
168
169llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-member page-type_translation');
170
171$form = new Form($db);
172$formadmin = new FormAdmin($db);
173
174$head = member_type_prepare_head($object);
175$titre = $langs->trans("MemberType".$object->id);
176
177// Calculate $cnt_trans
178$cnt_trans = 0;
179if (!empty($object->multilangs)) {
180 foreach ($object->multilangs as $key => $value) {
181 $cnt_trans++;
182 }
183}
184
185
186print dol_get_fiche_head($head, 'translation', $titre, 0, 'group');
187
188$linkback = '<a href="'.dol_buildpath('/adherents/type.php', 1).'">'.$langs->trans("BackToList").'</a>';
189
190dol_banner_tab($object, 'rowid', $linkback);
191
192print dol_get_fiche_end();
193
194
195
196/*
197 * Action bar
198 */
199print "\n<div class=\"tabsAction\">\n";
200
201if ($action == '') {
202 if ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer')) {
203 print '<a class="butAction" href="'.DOL_URL_ROOT.'/adherents/type_translation.php?action=create&token='.newToken().'&rowid='.$object->id.'">'.$langs->trans("Add").'</a>';
204 if ($cnt_trans > 0) {
205 print '<a class="butAction" href="'.DOL_URL_ROOT.'/adherents/type_translation.php?action=edit&token='.newToken().'&rowid='.$object->id.'">'.$langs->trans("Update").'</a>';
206 }
207 }
208}
209
210print "\n</div>\n";
211
212
213
214if ($action == 'edit') {
215 //WYSIWYG Editor
216 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
217
218 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
219 print '<input type="hidden" name="token" value="'.newToken().'">';
220 print '<input type="hidden" name="action" value="vedit">';
221 print '<input type="hidden" name="rowid" value="'.$object->id.'">';
222
223 if (!empty($object->multilangs)) {
224 foreach ($object->multilangs as $key => $value) {
225 $s = picto_from_langcode((string) $key);
226 print '<br>';
227 print '<div class="inline-block marginbottomonly">';
228 print($s ? $s.' ' : '').'<b>'.$langs->trans('Language_'.$key).':</b>';
229 print '</div>';
230 print '<div class="inline-block marginbottomonly floatright">';
231 print '<a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&action=delete&token='.newToken().'&langtodelete='.$key.'">'.img_delete('', 'class="valigntextbottom"')."</a><br>";
232 print '</div>';
233
234 print '<div class="underbanner clearboth"></div>';
235 print '<table class="border centpercent">';
236 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>';
237 print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
238 $doleditor = new DolEditor("desc-$key", $object->multilangs[$key]["description"], '', 160, 'dolibarr_notes', '', false, true, isModEnabled('fckeditor') && getDolGlobalInt('FCKEDITOR_ENABLE_SOCIETE'), ROWS_3, '90%');
239 $doleditor->Create();
240 print '</td></tr>';
241 print '</td></tr>';
242 print '</table>';
243 }
244 }
245
246 print $form->buttonsSaveCancel();
247
248 print '</form>';
249} elseif ($action != 'create') {
250 if (!empty($object->multilangs)) {
251 foreach ($object->multilangs as $key => $value) {
252 $s = picto_from_langcode((string) $key);
253 print '<div class="inline-block marginbottomonly">';
254 print($s ? $s.' ' : '').'<b>'.$langs->trans('Language_'.$key).':</b>';
255 print '</div>';
256 print '<div class="inline-block marginbottomonly floatright">';
257 print '<a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&action=delete&token='.newToken().'&langtodelete='.$key.'">'.img_delete('', 'class="valigntextbottom"').'</a>';
258 print '</div>';
259
260
261 print '<div class="fichecenter">';
262 print '<div class="underbanner clearboth"></div>';
263 print '<table class="border centpercent">';
264 print '<tr><td class="titlefieldcreate">'.$langs->trans('Label').'</td><td>'.$object->multilangs[$key]["label"].'</td></tr>';
265 print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>'.$object->multilangs[$key]["description"].'</td></tr>';
266 print '</table>';
267 print '</div>';
268
269 print '<br>';
270 }
271 }
272 if (!$cnt_trans && $action != 'create') {
273 print '<div class="opacitymedium">'.$langs->trans('NoTranslation').'</div>';
274 }
275}
276
277
278
279/*
280 * Form to add a new translation
281 */
282
283if ($action == 'create' && $user->hasRight('adherent', 'configurer')) {
284 //WYSIWYG Editor
285 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
286
287 print '<br>';
288 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
289 print '<input type="hidden" name="token" value="'.newToken().'">';
290 print '<input type="hidden" name="action" value="vadd">';
291 print '<input type="hidden" name="rowid" value="'.GETPOSTINT("rowid").'">';
292
293 print dol_get_fiche_head();
294
295 print '<table class="border centpercent">';
296 print '<tr><td class="tdtop titlefieldcreate fieldrequired">'.$langs->trans('Language').'</td><td>';
297 print $formadmin->select_language('', 'forcelangprod', 0, $object->multilangs, 1);
298 print '</td></tr>';
299 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>';
300 print '<tr><td class="tdtop">'.$langs->trans('Description').'</td><td>';
301 $doleditor = new DolEditor('desc', '', '', 160, 'dolibarr_notes', '', false, true, isModEnabled('fckeditor'), ROWS_3, '90%');
302 $doleditor->Create();
303 print '</td></tr>';
304
305 print '</table>';
306
307 print dol_get_fiche_end();
308
309 print $form->buttonsSaveCancel();
310
311 print '</form>';
312
313 print '<br>';
314}
315
316// End of page
317llxFooter();
318$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
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:71
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
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.