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