Supporto multilingua in configurazione

This commit is contained in:
Thomas Zilio 2019-08-02 13:21:21 +02:00
parent 64fe9439c0
commit 32b4d463d5
10 changed files with 219 additions and 70 deletions

View File

@ -34,19 +34,7 @@ function start_datatables() {
var id_parent = $this.data('idparent');
// Parametri di ricerca da url o sessione
var search = getUrlVars();
globals.search.forEach(function (value, index, array) {
if (search[array[index]] == undefined) {
search.push(array[index]);
search[array[index]] = array[value];
}
});
// Fix per l'URL encoding
search.forEach(function (value, index, array) {
search[array[index]] = decodeURIComponent(array[value]);
});
var search = getTableSearch();
var res = [];
$this.find("th").each(function () {
@ -236,12 +224,14 @@ function start_datatables() {
});
// Ricerca di base ereditata dalla sessione
search.forEach(function (value, index, array) {
var search = getTableSearch();
var keys = Object.keys(search);
keys.forEach(function (key) {
var exists = setInterval(function () {
input = $('#th_' + array[index].replace('search_', '') + ' input');
if (input.length || array[index] == 'id_module' || array[index] == 'id_record') {
input = $('#th_' + key.replace('search_', '') + ' input');
if (input.length || key == 'id_module' || key == 'id_record') {
clearInterval(exists);
if (input.val() == '') input.val(array[value]).trigger('keyup');
if (input.val() == '') input.val(search[key]).trigger('keyup');
}
}, 100);
});
@ -427,3 +417,16 @@ function searchFieldName(field) {
function searchTable(module_id, field, value) {
session_set('module_' + module_id + ',' + 'search_' + searchFieldName(field), value, 0);
}
function getTableSearch() {
// Parametri di ricerca da url o sessione
var search = getUrlVars();
globals.search.forEach(function (value, index, array) {
if (search[array[index]] == undefined) {
search[array[index]] = array[value];
}
});
return search;
}

View File

@ -80,20 +80,15 @@ function scrollToOffset(offset) {
/**
* Ritorna un array associativo con i parametri passati via GET
*/
function getUrlVars(url) {
var vars = [],
hash;
if (url == null)
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
else
var hashes = url.slice(url.indexOf('?') + 1).split('&');
for (var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
function getUrlVars() {
var search = window.location.search.substring(1);
if (!search) return {};
return vars;
var results = JSON.parse('{"' + search.replace(/&/g, '","').replace(/=/g,'":"') + '"}', function(key, value) {
return key === "" ? value : decodeURIComponent(value)
});
return results;
}
// Data e ora (orologio)

View File

@ -26,15 +26,15 @@ $HTMLHandlers = [];
$HTMLManagers = [];
// Lingua del progetto (per la traduzione e la conversione numerica)
$lang = 'it';
$lang = '|lang|';
// Personalizzazione della formattazione di timestamp, date e orari
$formatter = [
'timestamp' => 'd/m/Y H:i',
'date' => 'd/m/Y',
'time' => 'H:i',
'timestamp' => '|timestamp|',
'date' => '|date|',
'time' => '|time|',
'number' => [
'decimals' => ',',
'thousands' => '.',
'decimals' => '|decimals|',
'thousands' => '|thousands|',
],
];

View File

@ -149,7 +149,7 @@ if (!API\Response::isAPIRequest()) {
/* INTERNAZIONALIZZAZIONE */
// Istanziamento del gestore delle traduzioni del progetto
$lang = !empty($config['lang']) ? $config['lang'] : 'it';
$lang = !empty($config['lang']) ? $config['lang'] : $_GET['lang'];
$formatter = !empty($config['formatter']) ? $config['formatter'] : [];
$translator = trans();
$translator->addLocalePath($docroot.'/locale');

View File

@ -80,7 +80,6 @@ if (Auth::check()) {
});
</script>';
}
echo '

View File

@ -98,25 +98,25 @@ if (post('db_host') !== null) {
// Creazione della configurazione
if ($dbo->isConnected()) {
// Impostazioni di configurazione strettamente necessarie al funzionamento del progetto
$backup_config = '<?php
$new_config = file_get_contents(DOCROOT.'/config.example.php');
$backup_dir = __DIR__.\'/backup/\';
$db_host = \'|host|\';
$db_username = \'|username|\';
$db_password = \'|password|\';
$db_name = \'|database|\';
';
$new_config = (file_exists($docroot.'/config.example.php')) ? file_get_contents($docroot.'/config.example.php') : $backup_config;
$decimals = post('decimal_separator');
$thousands = post('thousand_separator');
$decimals = $decimals == 'dot' ? '.' : ',';
$thousands = $thousands == 'dot' ? '.' : $thousands;
$thousands = $thousands == 'comma' ? ',' : $thousands;
$values = [
'|host|' => $db_host,
'|username|' => $db_username,
'|password|' => $db_password,
'|database|' => $db_name,
'|lang|' => post('lang'),
'|timestamp|' => post('timestamp_format'),
'|date|' => post('date_format'),
'|time|' => post('time_format'),
'|decimals|' => $decimals,
'|thousands|' => $thousands,
];
$new_config = str_replace(array_keys($values), $values, $new_config);
@ -262,9 +262,9 @@ if (empty($creation) && (!file_exists('config.inc.php') || !$valid_config)) {
if($(this).closest("form").parsley().validate()){
prev_html = $("#install").html();
$("#install").html("<i class=\'fa fa-spinner fa-pulse fa-fw\'></i> '.tr('Attendere').'...");
$("#install").prop(\'disabled\', true);
$("#test").prop(\'disabled\', true);
$("#install").html("<i class=\'fa fa-spinner fa-pulse fa-fw\'></i> '.tr('Attendere').'...");
$("#install").prop("disabled", true);
$("#test").prop("disabled", true);
$("#config-form").submit();
}
@ -274,9 +274,9 @@ if (empty($creation) && (!file_exists('config.inc.php') || !$valid_config)) {
$("#test").on("click", function(){
if($(this).closest("form").parsley().validate()){
prev_html = $("#test").html();
$("#test").html("<i class=\'fa fa-spinner fa-pulse fa-fw\'></i> '.tr('Attendere').'...");
$("#test").prop(\'disabled\', true);
$("#install").prop(\'disabled\', true);
$("#test").html("<i class=\'fa fa-spinner fa-pulse fa-fw\'></i> '.tr('Attendere').'...");
$("#test").prop("disabled", true);
$("#install").prop("disabled", true);
$(this).closest("form").ajaxSubmit({
url: "'.$rootdir.'/index.php",
data: {
@ -287,15 +287,17 @@ if (empty($creation) && (!file_exists('config.inc.php') || !$valid_config)) {
data = parseFloat(data.trim());
$("#test").html(prev_html);
$("#test").prop(\'disabled\', false);
$("#install").prop(\'disabled\', false);
$("#test").prop("disabled", false);
$("#install").prop("disabled", false);
if(data == 0){
swal("'.tr('Errore della configurazione').'", "'.tr('La configurazione non è corretta').'.", "error");
} else if(data == 1){
swal("'.tr('Permessi insufficienti').'", "'.tr("L'utente non possiede permessi sufficienti per il testing della connessione. Potresti rilevare problemi in fase di installazione.").'.", "error");
} else {
swal("'.tr('Configurazione corretta').'", "'.tr('Ti sei connesso con successo al database').'. '.tr("Clicca su 'Installa' per proseguire").'.", "success");
swal("'.tr('Configurazione corretta').'", "'.tr('Ti sei connesso con successo al database').'. '.tr('Clicca su _BTN_ per proseguire', [
'_BTN_' => "'".tr('Installa')."'",
]).'.", "success");
}
},
error: function(data) {
@ -314,9 +316,87 @@ if (empty($creation) && (!file_exists('config.inc.php') || !$valid_config)) {
<h3 class="box-title">'.tr('OpenSTAManager').'</h3>
</div>
<div class="box-body" id="smartwizard">';
<div class="box-body" id="smartwizard">
<span class="pull-right col-md-4">
<select class="form-control hide" id="language" required="1">';
$languages = [
'it' => [
'title' => tr('Italiano'),
'flag' => 'IT',
],
'en' => [
'title' => tr('Inglese'),
'flag' => 'GB',
],
];
$current = trans()->getCurrentLocale();
foreach ($languages as $code => $language) {
echo '
<option data-country="'.$language['flag'].'" value="'.$code.'" '.($code == $current ? 'selected' : '').'>'.$language['title'].'</option>';
}
echo '
</select>
<script>
var flag_link = "https://lipis.github.io/flag-icon-css/flags/4x3/|flag|.svg";
$(document).ready(function() {
$.ajax({
url: flag_link.replace("|flag|", "it"),
success: function(){
initLanguage(true);
},
error: function(){
initLanguage(false);
},
timeout: 500
});
});
function initLanguage(flag) {
$("#language").removeClass("hide");
$("#language").select2({
theme: "bootstrap",
templateResult: function(item) {
if (!item.id || !flag) {
return item.text;
}
var element = $(item.element);
var img = $("<img>", {
class: "img-flag",
width: 26,
src: flag_link.replace("|flag|", element.data("country").toLowerCase()),
});
var span = $("<span>", {
text: " " + item.text
});
span.prepend(img);
return span;
}
});
$("#language").on("change", function(){
if ($(this).val()) {
var location = window.location;
var url = location.protocol + "//" + location.host + "" + location.pathname;
var parameters = getUrlVars();
parameters.lang = $(this).val();
redirect(url, parameters);
}
});
}
</script>
</span>
<ul>
<li><a href="#step-1">
<h3>'.tr('Requisiti').'</h3>
@ -363,7 +443,7 @@ if (empty($creation) && (!file_exists('config.inc.php') || !$valid_config)) {
<div class="row">
<div class="col-md-8">
<span class="pull-left" title='.tr('Visiona e accetta la licenza per proseguire').' >'.tr('Accetti la licenza GPLv3 di OpenSTAManager?').'*</span>
<span class="pull-left" title="'.tr('Visiona e accetta la licenza per proseguire').'">'.tr('Accetti la licenza GPLv3 di OpenSTAManager?').'*</span>
</div>
<form class="col-md-4">
@ -390,17 +470,77 @@ if (empty($creation) && (!file_exists('config.inc.php') || !$valid_config)) {
<p>'.tr('Non hai ancora configurato OpenSTAManager').'.</p>
<p><small class="help-block">'.tr('Configura correttamente il software con i seguenti parametri (modificabili successivamente dal file _FILE_)', [
'_FILE_' => '<b>config.inc.php</b>',
]).'</small></p>';
]).'</small></p>
<hr>';
// Form dei parametri
echo '
<form action="?action=updateconfig&firstuse=true" method="post" id="config-form">
<input type="hidden" name="lang" value="'.trans()->getCurrentLocale().'">
<h4>'.tr('Formato date').'</h4>
<div class="row">
<div class="col-md-4">
{[ "type": "text", "label": "'.tr('Formato data lunga').'", "name": "timestamp_format", "value": "d/m/Y H:i", "required": 1 ]}
</div>
<div class="col-md-4">
{[ "type": "text", "label": "'.tr('Formato data corta').'", "name": "date_format", "value": "d/m/Y", "required": 1 ]}
</div>
<div class="col-md-4">
{[ "type": "text", "label": "'.tr('Formato orario').'", "name": "time_format", "value": "H:i", "required": 1 ]}
</div>
</div>
<small>'.tr('I formati sono impostabili attraverso lo standard previsto da PHP: _LINK_', [
'_LINK_' => '<a href="https://www.php.net/manual/en/function.date.php#refsect1-function.date-parameters">https://www.php.net/manual/en/function.date.php#refsect1-function.date-parameters</a>',
]).'.</small>
<hr>';
if (class_exists('NumberFormatter')) {
$list = [
[
'id' => 'comma',
'text' => tr('Virgola'),
],
[
'id' => 'dot',
'text' => tr('Punto'),
],
];
echo '
<h4>'.tr('Formato numeri').'</h4>
<div class="row">
<div class="col-md-6">
{[ "type": "select", "label": "'.tr('Separatore dei decimali').'", "name": "decimal_separator", "value": "comma", "values": '.json_encode($list).', "required": 1 ]}
</div>
<div class="col-md-6">
{[ "type": "select", "label": "'.tr('Separatore delle migliaia').'", "name": "thousand_separator", "value": "dot", "values": '.json_encode($list).' ]}
</div>
</div>
<small>'.tr("Si consiglia l'abilitazione dell'estensione _EXT_ di PHP", [
'_EXT_' => 'intl',
]).'.</small>
<hr>';
}
echo '
<h4>'.tr('Database').'</h4>
<div class="row">';
// db_host
echo '
<div class="col-md-12">
{[ "type": "text", "label": "'.tr('Host del database').'", "name": "db_host", "placeholder": "'.tr("Indirizzo dell'host del database").'", "value": "'.$host.'", "help": "'.tr('Esempio').': localhost", "show-help": 0, "required": 1 ]}
{[ "type": "text", "label": "'.tr('Host del database').'", "name": "db_host", "placeholder": "'.tr('Host').'", "value": "'.$host.'", "help": "'.tr('Esempio').': localhost", "show-help": 0, "required": 1 ]}
</div>
</div>
@ -409,19 +549,19 @@ if (empty($creation) && (!file_exists('config.inc.php') || !$valid_config)) {
// db_username
echo '
<div class="col-md-4">
{[ "type": "text", "label": "'.tr("Username dell'utente MySQL").'", "name": "db_username", "placeholder": "'.tr("Username dell'utente MySQL").'", "value": "'.$username.'", "help": "'.tr('Esempio').': root", "show-help": 0, "required": 1 ]}
{[ "type": "text", "label": "'.tr("Username dell'utente MySQL").'", "name": "db_username", "placeholder": "'.tr('Username').'", "value": "'.$username.'", "help": "'.tr('Esempio').': root", "show-help": 0, "required": 1 ]}
</div>';
// db_password
echo '
<div class="col-md-4">
{[ "type": "password", "label": "'.tr("Password dell'utente MySQL").'", "name": "db_password", "placeholder": "'.tr("Password dell'utente MySQL").'", "value": "'.$password.'", "help": "'.tr('Esempio').': mysql", "show-help": 0 ]}
{[ "type": "password", "label": "'.tr("Password dell'utente MySQL").'", "name": "db_password", "placeholder": "'.tr('Password').'", "value": "'.$password.'", "help": "'.tr('Esempio').': mysql", "show-help": 0 ]}
</div>';
// db_name
echo '
<div class="col-md-4">
{[ "type": "text", "label": "'.tr('Nome del database').'", "name": "db_name", "placeholder": "'.tr('Nome del database').'", "value": "'.$name.'", "help": "'.tr('Esempio').': openstamanager", "show-help": 0, "required": 1 ]}
{[ "type": "text", "label": "'.tr('Nome del database').'", "name": "db_name", "placeholder": "'.tr('Database').'", "value": "'.$name.'", "help": "'.tr('Esempio').': openstamanager", "show-help": 0, "required": 1 ]}
</div>
</div>';

View File

@ -19,6 +19,7 @@ $settings = [
'Conto predefinito fatture di acquisto' => true,
"Percentuale ritenuta d'acconto" => false,
"Causale ritenuta d'acconto" => false,
'Valuta' => true,
];
if (!empty(setting("Percentuale ritenuta d'acconto"))) {

View File

@ -21,7 +21,7 @@ echo '<!DOCTYPE html>
<link href="'.$paths['img'].'/favicon.png" rel="icon" type="image/x-icon" />';
if (file_exists(DOCROOT.'/manifest.json')){
if (file_exists(DOCROOT.'/manifest.json')) {
echo '
<link rel="manifest" href="'.ROOTDIR.'/manifest.json">';
}

View File

@ -306,9 +306,9 @@ switch (post('op')) {
$rs = $dbo->fetchArray('SELECT * FROM co_righe_contratti WHERE idcontratto='.prepare($id_record));
for ($i = 0; $i < sizeof($rs); ++$i) {
unset( $rs[$i]['id'] );
unset( $rs[$i]['created_at'] );
unset( $rs[$i]['updated_at'] );
unset($rs[$i]['id']);
unset($rs[$i]['created_at']);
unset($rs[$i]['updated_at']);
$rs[$i]['idcontratto'] = $new_idcontratto;
$dbo->insert('co_righe_contratti', $rs);

View File

@ -290,6 +290,17 @@ class App
$db_password = '';
$db_name = '';
$port = '';
$lang = '';
$formatter = [
'timestamp' => 'd/m/Y H:i',
'date' => 'd/m/Y',
'time' => 'H:i',
'number' => [
'decimals' => ',',
'thousands' => '.',
],
];
return get_defined_vars();
}