2021-09-03 20:14:30 +02:00
|
|
|
<?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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
include_once __DIR__.'/../../core.php';
|
|
|
|
|
|
|
|
echo '
|
|
|
|
<table class="table table-hover table-bordered table-condensed">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>'.tr('Nome').'</th>
|
|
|
|
<th class="text-center">'.tr('Versione').'</th>
|
|
|
|
<th class="text-center">'.tr('Stato').'</th>
|
|
|
|
<th class="text-center">#</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
|
|
|
|
<tbody>';
|
|
|
|
|
|
|
|
$moduli = Modules::getHierarchy();
|
|
|
|
echo renderElencoModuli($moduli);
|
|
|
|
|
|
|
|
echo '
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
function disabilitaModulo(button){
|
|
|
|
const riga = $(button).closest("tr");
|
|
|
|
const id = riga.data("id");
|
|
|
|
|
|
|
|
const nome = riga.data("nome");
|
|
|
|
const tipo = riga.data("tipo");
|
|
|
|
const nome_tipo = riga.data("nome_tipo");
|
|
|
|
|
|
|
|
swal({
|
|
|
|
title: "'.tr('Disabilitare il _TYPE_?', [
|
2024-03-22 15:52:24 +01:00
|
|
|
'_TYPE_' => '" + nome_tipo + "',
|
|
|
|
]).'",
|
2021-09-03 20:14:30 +02:00
|
|
|
html: "'.tr('Sei sicuro di voler disabilitare il _TYPE_ _NAME_?', [
|
2024-03-22 15:52:24 +01:00
|
|
|
'_TYPE_' => '" + nome_tipo + "',
|
|
|
|
'_NAME_' => '" + nome + "',
|
|
|
|
]).'",
|
2021-09-03 20:14:30 +02:00
|
|
|
type: "warning",
|
|
|
|
showCancelButton: true,
|
|
|
|
confirmButtonText: "'.tr('Continua').'"
|
|
|
|
}).then(function (result) {
|
|
|
|
let restore = buttonLoading(button);
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: globals.rootdir + "/actions.php",
|
|
|
|
type: "POST",
|
|
|
|
dataType: "JSON",
|
|
|
|
data: {
|
|
|
|
id_module: globals.id_module,
|
|
|
|
op: "disabilita-modulo",
|
|
|
|
tipo: tipo,
|
|
|
|
id: id,
|
|
|
|
},
|
|
|
|
success: function (response) {
|
|
|
|
caricaElencoModuli();
|
|
|
|
renderMessages();
|
|
|
|
},
|
|
|
|
error: function() {
|
|
|
|
buttonRestore(button, restore);
|
|
|
|
|
|
|
|
swal({
|
|
|
|
type: "error",
|
|
|
|
title: globals.translations.ajax.error.title,
|
|
|
|
text: globals.translations.ajax.error.text,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function abilitaModulo(button) {
|
|
|
|
const riga = $(button).closest("tr");
|
|
|
|
const id = riga.data("id");
|
|
|
|
|
|
|
|
const nome = riga.data("nome");
|
|
|
|
const tipo = riga.data("tipo");
|
|
|
|
const nome_tipo = riga.data("nome_tipo");
|
|
|
|
|
|
|
|
swal({
|
|
|
|
title: "'.tr('Abilitare il _TYPE_?', [
|
2024-03-22 15:52:24 +01:00
|
|
|
'_TYPE_' => '" + nome_tipo + "',
|
|
|
|
]).'",
|
2021-09-03 20:14:30 +02:00
|
|
|
html: "'.tr('Sei sicuro di voler abilitare il _TYPE_ _NAME_?', [
|
2024-03-22 15:52:24 +01:00
|
|
|
'_TYPE_' => '" + nome_tipo + "',
|
|
|
|
'_NAME_' => '" + nome + "',
|
|
|
|
]).'",
|
2021-09-03 20:14:30 +02:00
|
|
|
type: "warning",
|
|
|
|
showCancelButton: true,
|
|
|
|
confirmButtonText: "'.tr('Continua').'"
|
|
|
|
}).then(function (result) {
|
|
|
|
let restore = buttonLoading(button);
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: globals.rootdir + "/actions.php",
|
|
|
|
type: "POST",
|
|
|
|
dataType: "JSON",
|
|
|
|
data: {
|
|
|
|
id_module: globals.id_module,
|
|
|
|
op: "abilita-modulo",
|
|
|
|
tipo: tipo,
|
|
|
|
id: id,
|
|
|
|
},
|
|
|
|
success: function (response) {
|
|
|
|
caricaElencoModuli();
|
|
|
|
renderMessages();
|
|
|
|
},
|
|
|
|
error: function() {
|
|
|
|
buttonRestore(button, restore);
|
|
|
|
|
|
|
|
swal({
|
|
|
|
type: "error",
|
|
|
|
title: globals.translations.ajax.error.title,
|
|
|
|
text: globals.translations.ajax.error.text,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function abilitaSottoModuli(button) {
|
|
|
|
const riga = $(button).closest("tr");
|
|
|
|
const id = riga.data("id");
|
|
|
|
|
|
|
|
const nome = riga.data("nome");
|
|
|
|
const tipo = riga.data("tipo");
|
|
|
|
const nome_tipo = riga.data("nome_tipo");
|
|
|
|
|
|
|
|
swal({
|
|
|
|
title: "'.tr('Abilitare tutti i sotto-moduli?').'",
|
|
|
|
html: "'.tr('Sei sicuro di voler abilitare tutti i sotto-moduli del modulo _NAME_?', [
|
2024-03-22 15:52:24 +01:00
|
|
|
'_NAME_' => '" + nome + "',
|
|
|
|
]).'",
|
2021-09-03 20:14:30 +02:00
|
|
|
type: "warning",
|
|
|
|
showCancelButton: true,
|
|
|
|
confirmButtonText: "'.tr('Continua').'"
|
|
|
|
}).then(function (result) {
|
|
|
|
let restore = buttonLoading(button);
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: globals.rootdir + "/actions.php",
|
|
|
|
type: "POST",
|
|
|
|
dataType: "JSON",
|
|
|
|
data: {
|
|
|
|
id_module: globals.id_module,
|
|
|
|
op: "abilita-sotto-modulo",
|
|
|
|
tipo: tipo,
|
|
|
|
id: id,
|
|
|
|
},
|
|
|
|
success: function (response) {
|
|
|
|
caricaElencoModuli();
|
|
|
|
renderMessages();
|
|
|
|
},
|
|
|
|
error: function() {
|
|
|
|
buttonRestore(button, restore);
|
|
|
|
|
|
|
|
swal({
|
|
|
|
type: "error",
|
|
|
|
title: globals.translations.ajax.error.title,
|
|
|
|
text: globals.translations.ajax.error.text,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function rimuoviModulo(button) {
|
|
|
|
const riga = $(button).closest("tr");
|
|
|
|
const id = riga.data("id");
|
|
|
|
|
|
|
|
const nome = riga.data("nome");
|
|
|
|
const tipo = riga.data("tipo");
|
|
|
|
const nome_tipo = riga.data("nome_tipo");
|
|
|
|
|
|
|
|
swal({
|
|
|
|
title: "'.tr('Rimuovere il _TYPE_?', [
|
2024-03-22 15:52:24 +01:00
|
|
|
'_TYPE_' => '" + nome_tipo + "',
|
|
|
|
]).'",
|
2021-09-03 20:14:30 +02:00
|
|
|
html: "'.tr('Sei sicuro di voler rimuovere il _TYPE_ _NAME_?', [
|
2024-03-22 15:52:24 +01:00
|
|
|
'_TYPE_' => '" + nome_tipo + "',
|
|
|
|
'_NAME_' => '" + nome + "',
|
|
|
|
]).'<br>'.tr('Questa operazione è irreversibile e provocherà la potenziale perdita dei dati attualmente collegati al _TYPE_', [
|
|
|
|
'_TYPE_' => '" + nome_tipo + "',
|
|
|
|
]).'.",
|
2021-09-03 20:14:30 +02:00
|
|
|
type: "warning",
|
|
|
|
showCancelButton: true,
|
|
|
|
confirmButtonText: "'.tr('Continua').'"
|
|
|
|
}).then(function (result) {
|
|
|
|
let restore = buttonLoading(button);
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: globals.rootdir + "/actions.php",
|
|
|
|
type: "POST",
|
|
|
|
dataType: "JSON",
|
|
|
|
data: {
|
|
|
|
id_module: globals.id_module,
|
|
|
|
op: "rimuovi-modulo",
|
|
|
|
tipo: tipo,
|
|
|
|
id: id,
|
|
|
|
},
|
|
|
|
success: function (response) {
|
|
|
|
caricaElencoModuli();
|
|
|
|
renderMessages();
|
|
|
|
},
|
|
|
|
error: function() {
|
|
|
|
buttonRestore(button, restore);
|
|
|
|
|
|
|
|
swal({
|
|
|
|
type: "error",
|
|
|
|
title: globals.translations.ajax.error.title,
|
|
|
|
text: globals.translations.ajax.error.text,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.depth-0 {
|
|
|
|
filter: brightness(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
.depth-1 {
|
|
|
|
filter: brightness(1.05);
|
|
|
|
}
|
|
|
|
|
|
|
|
.depth-2 {
|
|
|
|
filter: brightness(1.1);
|
|
|
|
}
|
|
|
|
|
|
|
|
.depth-3 {
|
|
|
|
filter: brightness(1.15);
|
|
|
|
}
|
|
|
|
</style>';
|
|
|
|
|
|
|
|
function renderElencoModuli($elenco, $depth = 0)
|
|
|
|
{
|
|
|
|
$versione_gestionale = Update::getVersion();
|
|
|
|
$moduli_sempre_attivi = ['Utenti e permessi', 'Stato dei servizi'];
|
|
|
|
|
|
|
|
$result = '';
|
|
|
|
foreach ($elenco as $record) {
|
|
|
|
$record_bloccato = in_array($record['name'], $moduli_sempre_attivi);
|
|
|
|
|
|
|
|
$is_plugin = !empty($record['idmodule_to']);
|
|
|
|
$nome_tipo = string_lowercase($is_plugin ? tr('Plugin') : tr('Modulo'));
|
|
|
|
|
|
|
|
// Render per sotto-moduli
|
|
|
|
$sotto_moduli = renderElencoModuli($record['all_children'], $depth + 1);
|
|
|
|
|
|
|
|
$elenco_plugin = null;
|
|
|
|
if (empty($record['idmodule_to'])) {
|
|
|
|
$plugins = database()->table('zz_plugins')
|
2024-03-05 16:01:45 +01:00
|
|
|
->selectRaw('zz_plugins.*, zz_plugins_lang.title as title')
|
2024-03-21 15:06:51 +01:00
|
|
|
->join('zz_plugins_lang', function ($join) {
|
|
|
|
$join->on('zz_plugins.id', '=', 'zz_plugins_lang.id_record')
|
2024-03-22 15:52:24 +01:00
|
|
|
->where('zz_plugins_lang.id_lang', '=', Models\Locale::getDefault()->id);
|
2024-03-21 15:06:51 +01:00
|
|
|
})
|
2021-09-03 20:14:30 +02:00
|
|
|
->where('idmodule_to', '=', $record['id'])
|
2024-04-09 12:18:08 +02:00
|
|
|
->get()->map(fn ($i) => (array) $i)->toArray();
|
2021-09-03 20:14:30 +02:00
|
|
|
|
|
|
|
$elenco_plugin = renderElencoModuli($plugins, $depth + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// COMPATIBILITA'
|
|
|
|
// Controllo per ogni versione se la regexp combacia per dire che è compatibile o meno
|
|
|
|
$compatibile = false;
|
|
|
|
$versioni_compatibili = explode(',', $record['compatibility']);
|
|
|
|
foreach ($versioni_compatibili as $versione) {
|
|
|
|
$compatibile = (preg_match('/'.$versione.'/', $versione_gestionale)) ? true : $compatibile;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($compatibile) {
|
|
|
|
$class = ($record['enabled']) ? 'success' : 'warning';
|
|
|
|
} else {
|
|
|
|
$class = 'danger';
|
|
|
|
}
|
|
|
|
|
|
|
|
$result .= '
|
|
|
|
<tr class="'.$class.' depth-'.$depth.'" data-id="'.$record['id'].'" data-nome='.json_encode($record['title']).' data-tipo="'.($is_plugin ? 'plugin' : 'module').'" data-nome_tipo='.json_encode($nome_tipo).'>
|
|
|
|
<td>
|
|
|
|
'.str_repeat(' ', $depth * 4).'- '.$record['title'].'
|
|
|
|
'.($compatibile ? '' :
|
2024-05-16 18:02:50 +02:00
|
|
|
'<div class="tip pull-right" data-widget="tooltip" title="'.tr('Non compatibile!').' '.tr('Questo _TYPE_ è compatibile solo con le versioni: _LIST_', [
|
2021-09-03 20:14:30 +02:00
|
|
|
'_TYPE_' => $nome_tipo,
|
|
|
|
'_LIST_' => $record['compatibility'],
|
|
|
|
]).'">
|
2024-05-16 18:02:50 +02:00
|
|
|
<span class="badge badge-danger">
|
2021-09-03 20:14:30 +02:00
|
|
|
<i class="fa fa-warning" title="'.tr('Non compatibile!').'"></i>
|
|
|
|
</span>
|
|
|
|
</div>'
|
2024-01-15 15:30:45 +01:00
|
|
|
).'
|
2021-09-03 20:14:30 +02:00
|
|
|
|
|
|
|
'.($is_plugin ? '<span class="badge pull-right" style="margin-right: 5px">'.tr('Plugin').'</span>' : '').'
|
|
|
|
</td>
|
|
|
|
<td class="text-center">'.$record['version'].'</td>
|
|
|
|
<td class="text-center">';
|
|
|
|
|
|
|
|
// Possibilità di disabilitare o abilitare il moduli/plugin
|
|
|
|
if (!$record_bloccato) {
|
|
|
|
if ($record['enabled']) {
|
|
|
|
$result .= '
|
2024-05-16 18:02:50 +02:00
|
|
|
<div class="tip" data-widget="tooltip" title="'.tr('Questo _TYPE_ è abilitato: clicca qui per disabilitarlo', [
|
2021-09-03 20:14:30 +02:00
|
|
|
'_TYPE_' => $nome_tipo,
|
|
|
|
]).'">
|
|
|
|
<button type="button" class="btn btn-warning btn-xs" onclick="disabilitaModulo(this)">
|
|
|
|
<i class="fa fa-power-off" title="'.tr('Disabilita').'"></i>
|
|
|
|
</button>
|
|
|
|
</div>';
|
|
|
|
|
|
|
|
// Possibilità di abilitare tutti i sottomoduli
|
|
|
|
$sotto_moduli_disabilitato = strpos($sotto_moduli, 'fa fa-plug') !== false;
|
|
|
|
if ($sotto_moduli_disabilitato) {
|
|
|
|
$result .= '
|
2024-05-16 18:02:50 +02:00
|
|
|
<div class="tip" data-widget="tooltip" title="'.tr('Abilita tutti i sotto-moduli').'">
|
2021-09-03 20:14:30 +02:00
|
|
|
<button type="button" class="btn btn-success btn-xs" onclick="abilitaSottoModuli(this)">
|
|
|
|
<i class="fa fa-recycle" title="'.tr('Abilita sotto-moduli').'"></i>
|
|
|
|
</button>
|
|
|
|
</div>';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$result .= '
|
2024-05-16 18:02:50 +02:00
|
|
|
<div class="tip" data-widget="tooltip" title="'.tr('Questo _TYPE_ è disabilitato: clicca qui per abilitarlo', [
|
2021-09-03 20:14:30 +02:00
|
|
|
'_TYPE_' => $nome_tipo,
|
|
|
|
]).'">
|
|
|
|
<button type="button" class="btn btn-success btn-xs" onclick="abilitaModulo(this)">
|
|
|
|
<i class="fa fa-plug" title="'.tr('Abilita').'"></i>
|
|
|
|
</button>
|
|
|
|
</div>';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$result .= '
|
2024-05-16 18:02:50 +02:00
|
|
|
<div class="tip" data-widget="tooltip" title="'.tr('Questo _TYPE_ non può essere disabilitato', [
|
2024-03-22 15:52:24 +01:00
|
|
|
'_TYPE_' => $nome_tipo,
|
|
|
|
]).'">
|
2021-09-03 20:14:30 +02:00
|
|
|
<i class="fa fa-eye" title="'.tr('Modulo sempre abilitato').'"></i>
|
|
|
|
</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$result .= '
|
|
|
|
</td>
|
|
|
|
<td class="text-center">';
|
|
|
|
|
|
|
|
// Possibilità di disinstallare solo se il modulo/plugin non è tra quelli predefiniti
|
|
|
|
if (empty($record['default'])) {
|
|
|
|
$result .= '
|
2024-05-16 18:02:50 +02:00
|
|
|
<div class="tip" data-widget="tooltip" title="'.tr('Puoi disintallare questo modulo: clicca qui per procedere').'">
|
2021-09-03 20:14:30 +02:00
|
|
|
<button type="button" class="btn btn-danger btn-xs" onclick="rimuoviModulo(this)">
|
|
|
|
<i class="fa fa-trash" title="'.tr('Disinstalla').'"></i>
|
|
|
|
</button>
|
|
|
|
</div>';
|
|
|
|
} else {
|
|
|
|
$result .= '
|
2024-05-16 18:02:50 +02:00
|
|
|
<div class="tip" data-widget="tooltip" title="'.tr('Questo _TYPE_ non può essere disinstallato', [
|
2024-03-22 15:52:24 +01:00
|
|
|
'_TYPE_' => $nome_tipo,
|
|
|
|
]).'">
|
2021-09-03 20:14:30 +02:00
|
|
|
<i class="fa fa-trash text-muted" title="'.tr('Modulo non disinstallabile').'"></i>
|
|
|
|
</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$result .= '
|
|
|
|
</td>
|
|
|
|
</tr>';
|
|
|
|
|
|
|
|
$result .= $elenco_plugin;
|
|
|
|
$result .= $sotto_moduli;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|