mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-10 08:30:48 +01:00
feat: aggiunta gestione impostazioni per utente
This commit is contained in:
parent
34204640d8
commit
3daafafece
@ -106,7 +106,20 @@ function get($param, $raw = false)
|
||||
*/
|
||||
function setting($name, $again = false)
|
||||
{
|
||||
return Setting::where('nome', '=', $name)->first()->valore;
|
||||
$setting = Setting::where('nome', '=', $name)->first();
|
||||
|
||||
$user = Auth::user();
|
||||
if ($user) {
|
||||
$user_options = json_decode($user->options, true) ?: [];
|
||||
}
|
||||
|
||||
if ($user_options['settings'][$setting->id] !== null) {
|
||||
$value = $user_options['settings'][$setting->id];
|
||||
} else {
|
||||
$value = $setting->valore;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -317,4 +317,23 @@ switch (filter('op')) {
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 'update_setting':
|
||||
|
||||
$id = filter('id');
|
||||
$valore = filter('valore', null, 1);
|
||||
|
||||
$user_options = json_decode($user->options, true) ?: [];
|
||||
$user_options['settings'][$id] = $valore;
|
||||
|
||||
$user->options = json_encode($user_options);
|
||||
$user->save();
|
||||
|
||||
echo json_encode([
|
||||
'result' => true,
|
||||
]);
|
||||
|
||||
flash()->info('Impostazione modificata con successo!');
|
||||
|
||||
break;
|
||||
}
|
@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
use Models\Module;
|
||||
use Models\Setting;
|
||||
|
||||
$skip_permissions = true;
|
||||
include_once __DIR__.'/../../core.php';
|
||||
@ -107,20 +108,10 @@ echo '
|
||||
|
||||
<div class="col-md-6">
|
||||
<div class="card card-info">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title">'.tr('Calendario interventi').'</h3>
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
<p>'.tr("Per accedere al calendario eventi attraverso l'API, accedi al seguente link").':</p>
|
||||
<a href="'.$link.'" target="_blank">'.$link.'</a>
|
||||
</div>
|
||||
|
||||
<div class="card-header">
|
||||
<h3 class="card-title">'.tr('Configurazione').'</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div>
|
||||
<p>'.tr("Per _ANDROID_, scarica un'applicazione dedicata dal _LINK_", [
|
||||
'_ANDROID_' => '<b>'.tr('Android').'</b>',
|
||||
'_LINK_' => '<a href="https://play.google.com/store/search?q=iCalSync&c=apps" target="_blank">'.tr('Play Store').'</a>',
|
||||
@ -136,7 +127,101 @@ echo '
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>';
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="card card-success">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title">'.tr('Impostazioni').'</h3>
|
||||
</div>
|
||||
|
||||
<div class="card-body">';
|
||||
$gruppi = Setting::selectRaw('sezione AS nome, COUNT(id) AS numero')
|
||||
->where('is_user_setting', 1)
|
||||
->groupBy(['sezione'])
|
||||
->orderBy('sezione')
|
||||
->get();
|
||||
|
||||
foreach ($gruppi as $key => $gruppo) {
|
||||
echo '
|
||||
<!-- Impostazioni della singola sezione -->
|
||||
<div class="card card-primary collapsed-card" title="'.$gruppo->nome.'">
|
||||
<div class="card-header clickable" title="'.$gruppo->nome.'" id="impostazioni-'.$key.'">
|
||||
<div class="card-title">'.tr('_SEZIONE_', [
|
||||
'_SEZIONE_' => $gruppo->nome,
|
||||
]).'</div>
|
||||
<div class="card-tools pull-right">
|
||||
<div class="badge">'.$gruppo->numero.'</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-body row"></div>
|
||||
</div>';
|
||||
}
|
||||
echo '
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<div class="card card-info">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title">'.tr('Calendario interventi').'</h3>
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
<p>'.tr("Per accedere al calendario eventi attraverso l'API, accedi al seguente link").':</p>
|
||||
<a href="'.$link.'" target="_blank">'.$link.'</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$("[id^=impostazioni]").click(function() {
|
||||
caricaSezione(this);
|
||||
});
|
||||
|
||||
function caricaSezione(header) {
|
||||
let card = $(header).closest(".card");
|
||||
card.toggleClass("collapsed-card");
|
||||
|
||||
// Controllo sul caricamento già effettuato
|
||||
let container = card.find(".card-body");
|
||||
if (container.html()){
|
||||
return ;
|
||||
}
|
||||
|
||||
// Caricamento della sezione di impostazioni
|
||||
let sezione = card.attr("title");
|
||||
localLoading(container, true);
|
||||
return $.get("'.$module->fileurl('sezione.php').'?id_module='.$module->id.'&sezione=" + sezione, function(data) {
|
||||
container.html(data);
|
||||
localLoading(container, false);
|
||||
});
|
||||
}
|
||||
|
||||
function salvaImpostazione(id, valore){
|
||||
$.ajax({
|
||||
url: "'.$module->fileurl('actions.php').'",
|
||||
cache: false,
|
||||
type: "POST",
|
||||
dataType: "JSON",
|
||||
data: {
|
||||
op: "update_setting",
|
||||
id_module: '.$module->id.',
|
||||
id: id,
|
||||
valore: valore,
|
||||
},
|
||||
success: function(data) {
|
||||
renderMessages();
|
||||
},
|
||||
error: function(data) {
|
||||
swal("'.tr('Errore').'", "'.tr('Errore durante il salvataggio dei dati').'", "error");
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>';
|
||||
|
||||
include_once App::filepath('include|custom|', 'bottom.php');
|
||||
|
54
modules/utenti/sezione.php
Normal file
54
modules/utenti/sezione.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/*
|
||||
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
|
||||
* Copyright (C) DevCode s.r.l.
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use Models\Setting;
|
||||
|
||||
include_once __DIR__.'/../../core.php';
|
||||
|
||||
$sezione = filter('sezione');
|
||||
$impostazioni = Setting::where('sezione', $sezione)->where('is_user_setting', 1)
|
||||
->get();
|
||||
$user_options = json_decode($user->options, true) ?: [];
|
||||
|
||||
foreach ($impostazioni as $impostazione) {
|
||||
echo '
|
||||
<div class="col-md-6">
|
||||
'.Settings::input($impostazione->id, false, $user_options['settings'][$impostazione->id]).'
|
||||
</div>
|
||||
|
||||
<script>';
|
||||
|
||||
if ($impostazione->tipo == 'time' || $impostazione->tipo == 'date') {
|
||||
echo '
|
||||
input("setting['.$impostazione->id.']");
|
||||
$(document).on("blur", "#setting'.$impostazione->id.'", function (e) {
|
||||
salvaImpostazione('.$impostazione->id.', $("#setting'.$impostazione->id.'").val());
|
||||
});
|
||||
';
|
||||
} else {
|
||||
echo '
|
||||
|
||||
input("setting['.$impostazione->id.']").change(function (){
|
||||
salvaImpostazione('.$impostazione->id.', input(this).get());
|
||||
});';
|
||||
}
|
||||
|
||||
echo '
|
||||
</script>';
|
||||
}
|
@ -153,10 +153,16 @@ class Settings
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function input($setting, $required = false)
|
||||
public static function input($setting, $required = false, $value_user = null)
|
||||
{
|
||||
$setting = Setting::where('nome', '=', $setting)->orWhere('id', '=', $setting)->first();
|
||||
|
||||
if ($value_user !== null) {
|
||||
$value = $value_user;
|
||||
} else {
|
||||
$value = $setting->valore;
|
||||
}
|
||||
|
||||
// Lista predefinita
|
||||
if (preg_match("/list\[(.+?)\]/", $setting->tipo, $m)) {
|
||||
$values = explode(',', $m[1]);
|
||||
@ -170,7 +176,7 @@ class Settings
|
||||
}
|
||||
|
||||
$result = '
|
||||
{[ "type": "select", "multiple": 0, "label": '.json_encode($setting->getTranslation('title')).', "readonly": "'.!$setting->editable.'", "name": "setting['.$setting->id.']", "values": '.json_encode($list).', "value": "'.$setting->valore.'", "required": "'.intval($required).'", "help": "'.$setting->getTranslation('help').'" ]}';
|
||||
{[ "type": "select", "multiple": 0, "label": '.json_encode($setting->getTranslation('title')).', "readonly": "'.!$setting->editable.'", "name": "setting['.$setting->id.']", "values": '.json_encode($list).', "value": "'.$value.'", "required": "'.intval($required).'", "help": "'.$setting->getTranslation('help').'" ]}';
|
||||
}
|
||||
|
||||
// Lista multipla
|
||||
@ -203,19 +209,19 @@ class Settings
|
||||
}
|
||||
|
||||
$result = '
|
||||
{[ "type": "select", "multiple": 1, "label": '.json_encode($setting->getTranslation('title')).', "readonly": "'.!$setting->editable.'", "name": "setting['.$setting->id.'][]", "values": '.json_encode($list).', "value": "'.$setting->valore.'", "required": "'.intval($required).'", "help": "'.$setting->getTranslation('help').'" ]}';
|
||||
{[ "type": "select", "multiple": 1, "label": '.json_encode($setting->getTranslation('title')).', "readonly": "'.!$setting->editable.'", "name": "setting['.$setting->id.'][]", "values": '.json_encode($list).', "value": "'.$value.'", "required": "'.intval($required).'", "help": "'.$setting->getTranslation('help').'" ]}';
|
||||
}
|
||||
|
||||
// Lista da query
|
||||
elseif (preg_match('/^query=(.+?)$/', $setting->tipo, $m)) {
|
||||
$result = '
|
||||
{[ "type": "select", "label": '.json_encode($setting->getTranslation('title')).', "readonly": "'.!$setting->editable.'", "name": "setting['.$setting->id.']", "values": "'.str_replace('"', '\"', $setting->tipo).'", "value": "'.$setting->valore.'", "required": "'.intval($required).'", "help": "'.$setting->getTranslation('help').'" ]}';
|
||||
{[ "type": "select", "label": '.json_encode($setting->getTranslation('title')).', "readonly": "'.!$setting->editable.'", "name": "setting['.$setting->id.']", "values": "'.str_replace('"', '\"', $setting->tipo).'", "value": "'.$value.'", "required": "'.intval($required).'", "help": "'.$setting->getTranslation('help').'" ]}';
|
||||
}
|
||||
|
||||
// Boolean (checkbox)
|
||||
elseif ($setting->tipo == 'boolean') {
|
||||
$result = '
|
||||
{[ "type": "checkbox", "label": '.json_encode($setting->getTranslation('title')).', "readonly": "'.!$setting->editable.'", "name": "setting['.$setting->id.']", "placeholder": "'.tr('Attivo').'", "value": "'.$setting->valore.'", "required": "'.intval($required).'", "help": "'.$setting->getTranslation('help').'" ]}';
|
||||
{[ "type": "checkbox", "label": '.json_encode($setting->getTranslation('title')).', "readonly": "'.!$setting->editable.'", "name": "setting['.$setting->id.']", "placeholder": "'.tr('Attivo').'", "value": "'.$value.'", "required": "'.intval($required).'", "help": "'.$setting->getTranslation('help').'" ]}';
|
||||
}
|
||||
|
||||
// Editor
|
||||
@ -225,7 +231,7 @@ class Settings
|
||||
'label' => json_encode($setting->getTranslation('title')),
|
||||
'readonly' => !$setting->editable,
|
||||
'name' => 'setting['.$setting->id.']',
|
||||
'value' => $setting->valore,
|
||||
'value' => $value,
|
||||
'required' => intval($required),
|
||||
'help' => $setting->getTranslation('help'),
|
||||
]);
|
||||
@ -234,7 +240,7 @@ class Settings
|
||||
// Campi di default
|
||||
elseif (in_array($setting->tipo, ['textarea', 'timestamp', 'date', 'time'])) {
|
||||
$result = '
|
||||
{[ "type": "'.$setting->tipo.'", "label": '.json_encode($setting->getTranslation('title')).', "readonly": "'.!$setting->editable.'", "name": "setting['.$setting->id.']", "value": '.json_encode($setting->valore).', "required": "'.intval($required).'", "help": "'.$setting->getTranslation('help').'" ]}';
|
||||
{[ "type": "'.$setting->tipo.'", "label": '.json_encode($setting->getTranslation('title')).', "readonly": "'.!$setting->editable.'", "name": "setting['.$setting->id.']", "value": '.json_encode($value).', "required": "'.intval($required).'", "help": "'.$setting->getTranslation('help').'" ]}';
|
||||
}
|
||||
|
||||
// Campo di testo
|
||||
@ -245,7 +251,7 @@ class Settings
|
||||
$tipo = $numerico ? 'number' : 'text';
|
||||
|
||||
$result = '
|
||||
{[ "type": "'.$tipo.'", "label": '.json_encode($setting->getTranslation('title')).', "readonly": "'.!$setting->editable.'", "name": "setting['.$setting->id.']", "value": "'.$setting->valore.'"'.($numerico && $setting->tipo == 'integer' ? ', "decimals": 0' : '').', "required": "'.intval($required).'", "help": "'.$setting->getTranslation('help').'" ]}';
|
||||
{[ "type": "'.$tipo.'", "label": '.json_encode($setting->getTranslation('title')).', "readonly": "'.!$setting->editable.'", "name": "setting['.$setting->id.']", "value": "'.$value.'"'.($numerico && $setting->tipo == 'integer' ? ', "decimals": 0' : '').', "required": "'.intval($required).'", "help": "'.$setting->getTranslation('help').'" ]}';
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
@ -219,3 +219,12 @@ ORDER BY
|
||||
|
||||
-- Allineamento plugin consuntivo
|
||||
UPDATE `zz_plugins` SET `directory` = 'consuntivo', `script` = '', `options` = 'custom' WHERE `name` = 'Consuntivo';
|
||||
|
||||
-- Aggiunta gestione impostazioni per utente
|
||||
ALTER TABLE `zz_users` ADD `options` TEXT NOT NULL;
|
||||
ALTER TABLE `zz_settings` ADD `is_user_setting` BOOLEAN NOT NULL;
|
||||
UPDATE `zz_settings` SET `is_user_setting` = '1' WHERE `zz_settings`.`nome` = 'Nascondere la barra dei plugin di default';
|
||||
UPDATE `zz_settings` SET `is_user_setting` = '1' WHERE `zz_settings`.`nome` = 'Nascondere la barra sinistra di default';
|
||||
UPDATE `zz_settings` SET `is_user_setting` = '1' WHERE `zz_settings`.`nome` = 'Sistema di firma ';
|
||||
UPDATE `zz_settings` SET `is_user_setting` = '1' WHERE `zz_settings`.`nome` = 'Inizio periodo calendario';
|
||||
UPDATE `zz_settings` SET `is_user_setting` = '1' WHERE `zz_settings`.`nome` = 'Fine periodo calendario';
|
||||
|
Loading…
x
Reference in New Issue
Block a user