* Copyright (C) 2007 Rodolphe Quiedeville * Copyright (C) 2010-2016 Destailleur Laurent * Copyright (C) 2015 Raphaël Doursenaud * Copyright (C) 2024 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * or see https://www.gnu.org/ */ /** * \file htdocs/categories/traduction.php * \ingroup categories * \brief Page of translation of categories */ // Load Dolibarr environment require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; // Load translation files required by the page $langs->loadLangs(array('categories', 'languages')); $id = GETPOSTINT('id'); $label = GETPOST('label', 'alpha'); $action = GETPOST('action', 'aZ09'); $cancel = GETPOST('cancel', 'alpha'); if ($id == '' && $label == '') { dol_print_error(null, 'Missing parameter id'); exit(); } $object = new Categorie($db); $result = $object->fetch($id, $label); if ($result <= 0) { dol_print_error($db, $object->error); exit; } $type = $object->type; if (is_numeric($type)) { $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility } // Security check $result = restrictedArea($user, 'categorie', $id, '&category'); $permissiontoadd = $user->hasRight('categorie', 'creer'); /* * Actions */ $error = 0; // return to translation view if cancelled if ($cancel == $langs->trans("Cancel")) { $action = ''; } // validation of addition if ($action == 'vadd' && $cancel != $langs->trans("Cancel") && $permissiontoadd) { $object->fetch($id); $current_lang = $langs->getDefaultLang(); // check parameters $forcelangprod = GETPOST('forcelangprod', 'alpha'); $libelle = GETPOST('libelle', 'alpha'); $desc = GETPOST('desc', 'restricthtml'); if (empty($forcelangprod)) { $error++; $object->errors[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Translation')); } if (!$error) { if (empty($libelle)) { $error++; $object->errors[] = $langs->trans('Language_'.$forcelangprod).' : '.$langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Label')); } if (!$error) { // update the object if ($forcelangprod == $current_lang) { $object->label = $libelle; $object->description = dol_htmlcleanlastbr($desc); } else { $object->multilangs[$forcelangprod]["label"] = $libelle; $object->multilangs[$forcelangprod]["description"] = dol_htmlcleanlastbr($desc); } // save in base / sauvegarde en base $res = $object->setMultiLangs($user); if ($res < 0) { $error++; } } } if ($error) { $action = 'add'; setEventMessages($object->error, $object->errors, 'errors'); } else { $action = ''; } } // validation of the edition if ($action == 'vedit' && $cancel != $langs->trans("Cancel") && $permissiontoadd) { $object->fetch($id); $current_lang = $langs->getDefaultLang(); foreach ($object->multilangs as $key => $value) { // recording of new values in the object $libelle = GETPOST('libelle-'.$key, 'alpha'); $desc = GETPOST('desc-'.$key, 'restricthtml'); if (empty($libelle)) { $error++; $object->errors[] = $langs->trans('Language_'.$key).' : '.$langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Label')); } if ($key == $current_lang) { $object->label = $libelle; $object->description = dol_htmlcleanlastbr($desc); } else { $object->multilangs[$key]["label"] = $libelle; $object->multilangs[$key]["description"] = dol_htmlcleanlastbr($desc); } } if (!$error) { $res = $object->setMultiLangs($user); if ($res < 0) { $error++; } } if ($error) { $action = 'edit'; setEventMessages($object->error, $object->errors, 'errors'); } else { $action = ''; } } /* * View */ $form = new Form($db); $formadmin = new FormAdmin($db); $formother = new FormOther($db); llxHeader("", "", $langs->trans("Translation")); $title = Categorie::$MAP_TYPE_TITLE_AREA[$type]; $head = categories_prepare_head($object, $type); // Calculate $cnt_trans $cnt_trans = 0; if (!empty($object->multilangs)) { foreach ($object->multilangs as $key => $value) { $cnt_trans++; } } print dol_get_fiche_head($head, 'translation', $langs->trans($title), -1, 'category'); $backtolist = (GETPOST('backtolist') ? GETPOST('backtolist') : DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.urlencode($type)); $linkback = ''.$langs->trans("BackToList").''; $object->next_prev_filter = 'type = '.((int) $object->type); $object->ref = $object->label; $morehtmlref = '
'.$langs->trans("Root").' >> '; $ways = $object->print_all_ways(" >> ", '', 1); foreach ($ways as $way) { $morehtmlref .= $way."
\n"; } $morehtmlref .= '
'; dol_banner_tab($object, 'label', $linkback, ($user->socid ? 0 : 1), 'label', 'label', $morehtmlref, '&type='.$type, 0, '', '', 1); print '
'; print '
'; print '
'; print ''; // Description print ''; // Color print ''; print '
'; print $langs->trans("Description").''; print dol_htmlentitiesbr($object->description); print '
'; print $langs->trans("Color").''; print $formother->showColor($object->color); print '
'; print '
'; print dol_get_fiche_end(); /* * Action bar */ print "\n
\n"; if ($action == '') { if ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer')) { print ''.$langs->trans('Add').''; if ($cnt_trans > 0) { print ''.$langs->trans('Update').''; } } } print "\n
\n"; if ($action == 'edit') { // WYSIWYG Editor require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; print '
'; print ''; print ''; print ''; print ''; if (!empty($object->multilangs)) { foreach ($object->multilangs as $key => $value) { print "
".$langs->trans('Language_'.$key)." :
"; print ''; // Label $libelle = (GETPOST('libelle-'.$key, 'alpha') ? GETPOST('libelle-'.$key, 'alpha') : ($object->multilangs[$key]['label'] ?? '')); print ''; // Desc $desc = (GETPOST('desc-'.$key) ? GETPOST('desc-'.$key) : ($object->multilangs[$key]['description'] ?? '')); print ''; print ''; print '
'.$langs->trans('Label').'
'.$langs->trans('Description').''; $doleditor = new DolEditor("desc-$key", $desc, '', 160, 'dolibarr_notes', '', false, true, isModEnabled('fckeditor') && getDolGlobalInt('FCKEDITOR_ENABLE_SOCIETE'), ROWS_3, '90%'); $doleditor->Create(); print '
'; } } print '
'; print $form->buttonsSaveCancel(); print '
'; } elseif ($action != 'add') { if ($cnt_trans) { print '
'; } if (!empty($object->multilangs)) { foreach ($object->multilangs as $key => $value) { $s = picto_from_langcode((string) $key); print ''; print ''; print ''; print ''; if (getDolGlobalString('CATEGORY_USE_OTHER_FIELD_IN_TRANSLATION')) { print ''; } print '
'.($s ? $s.' ' : '')." ".$langs->trans('Language_'.$key).": ".''.img_delete('', '').'
'.$langs->trans('Label').''.($object->multilangs[$key]["label"] ?? '').'
'.$langs->trans('Description').''.($object->multilangs[$key]["description"] ?? '').'
'.$langs->trans('Other').' ('.$langs->trans("NotYetAvailable").')'.($object->multilangs[$key]["other"] ?? '').'
'; } } if (!$cnt_trans && $action != 'add') { print '
'.$langs->trans('NoTranslation').'
'; } } /* * Form to add a new translation */ if ($action == 'add' && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) { //WYSIWYG Editor require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; print '
'; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans('Translation').''; print $formadmin->select_language(GETPOST('forcelangprod', 'alpha'), 'forcelangprod', 0, $object->multilangs); print '
'.$langs->trans('Label').'
'.$langs->trans('Description').''; $doleditor = new DolEditor('desc', GETPOST('desc', 'restricthtml'), '', 160, 'dolibarr_notes', '', false, true, isModEnabled('fckeditor') && getDolGlobalInt('FCKEDITOR_ENABLE_SOCIETE'), ROWS_3, '90%'); $doleditor->Create(); print '
'; print $form->buttonsSaveCancel(); print '
'; print '
'; } // End of page llxFooter(); $db->close();