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