From 32b4d463d58f4e00029ff94c2daf2bc3e5d9480c Mon Sep 17 00:00:00 2001 From: Thomas Zilio Date: Fri, 2 Aug 2019 13:21:21 +0200 Subject: [PATCH] Supporto multilingua in configurazione --- assets/src/js/functions/datatables.js | 37 ++--- assets/src/js/functions/functions.js | 21 ++- config.example.php | 12 +- core.php | 2 +- include/bottom.php | 1 - include/init/configuration.php | 196 ++++++++++++++++++++++---- include/init/init.php | 1 + include/top.php | 2 +- modules/contratti/actions.php | 6 +- src/App.php | 11 ++ 10 files changed, 219 insertions(+), 70 deletions(-) diff --git a/assets/src/js/functions/datatables.js b/assets/src/js/functions/datatables.js index a1890ece4..d7546ee19 100644 --- a/assets/src/js/functions/datatables.js +++ b/assets/src/js/functions/datatables.js @@ -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; +} diff --git a/assets/src/js/functions/functions.js b/assets/src/js/functions/functions.js index 9724652fa..8f62d6655 100644 --- a/assets/src/js/functions/functions.js +++ b/assets/src/js/functions/functions.js @@ -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) diff --git a/config.example.php b/config.example.php index f6abca406..bdb75c15b 100644 --- a/config.example.php +++ b/config.example.php @@ -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|', ], ]; diff --git a/core.php b/core.php index bf20527f9..3fce9a5a0 100644 --- a/core.php +++ b/core.php @@ -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'); diff --git a/include/bottom.php b/include/bottom.php index dfdf953d6..77a7abac2 100644 --- a/include/bottom.php +++ b/include/bottom.php @@ -80,7 +80,6 @@ if (Auth::check()) { }); '; - } echo ' diff --git a/include/init/configuration.php b/include/init/configuration.php index 005457e6f..720bb42b9 100644 --- a/include/init/configuration.php +++ b/include/init/configuration.php @@ -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 = ' $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(" '.tr('Attendere').'..."); - $("#install").prop(\'disabled\', true); - $("#test").prop(\'disabled\', true); + $("#install").html(" '.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(" '.tr('Attendere').'..."); - $("#test").prop(\'disabled\', true); - $("#install").prop(\'disabled\', true); + $("#test").html(" '.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)) {

'.tr('OpenSTAManager').'

-
'; +
+ + + + + +