2021-02-25 09:41:33 +01: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';
|
|
|
|
|
|
|
|
// Schermata di caricamento delle informazioni
|
|
|
|
echo '
|
2024-09-04 16:40:17 +02:00
|
|
|
<button class="btn btn-lg btn-block btn-primary" onclick="avviaControlli(this);">
|
2021-02-25 09:41:33 +01:00
|
|
|
<i class="fa fa-cog"></i> '.tr('Avvia controlli').'
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<div id="controlli"></div>
|
|
|
|
|
|
|
|
<div id="progress">
|
|
|
|
<div class="progress">
|
|
|
|
<div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%">
|
|
|
|
<span>0%</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<hr>
|
|
|
|
<p class="text-center">'.tr('Operazione in corso').': <span id="operazione"></span></p>
|
|
|
|
</div>
|
|
|
|
|
2024-05-16 18:02:50 +02:00
|
|
|
<div class="alert alert-info" id="card-loading">
|
2021-02-25 09:41:33 +01:00
|
|
|
<i class="fa fa-spinner fa-spin"></i> '.tr('Caricamento in corso').'...
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="alert alert-success hidden" id="no-problems">
|
|
|
|
<i class="fa fa-check"></i> '.tr('Non sono stati rilevati problemi!').'
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
var content = $("#controlli");
|
|
|
|
var loader = $("#progress");
|
2024-05-16 18:02:50 +02:00
|
|
|
var progress = $("#card-loading");
|
2021-02-25 09:41:33 +01:00
|
|
|
|
|
|
|
$(document).ready(function () {
|
|
|
|
loader.hide();
|
|
|
|
progress.hide();
|
|
|
|
})
|
|
|
|
|
2021-03-01 12:08:08 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param button
|
|
|
|
*/
|
2021-02-25 09:41:33 +01:00
|
|
|
function avviaControlli(button) {
|
|
|
|
var restore = buttonLoading(button);
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: globals.rootdir + "/actions.php",
|
|
|
|
type: "GET",
|
|
|
|
dataType: "JSON",
|
|
|
|
data: {
|
|
|
|
id_module: globals.id_module,
|
|
|
|
op: "controlli-disponibili",
|
|
|
|
},
|
|
|
|
success: async function(controlli) {
|
|
|
|
// Ripristino pulsante
|
|
|
|
buttonRestore(button, restore);
|
|
|
|
$(button).hide();
|
|
|
|
|
|
|
|
// Visualizzazione loader
|
|
|
|
loader.show();
|
|
|
|
progress.show();
|
|
|
|
|
|
|
|
let number = 0;
|
|
|
|
let total = controlli.length;
|
|
|
|
for (const controllo of controlli) {
|
|
|
|
// Informazione grafica di progressione
|
|
|
|
number ++;
|
|
|
|
let percentage = Math.round(number / total * 100);
|
|
|
|
percentage = percentage > 100 ? 100 : percentage;
|
|
|
|
setPercentage(percentage);
|
|
|
|
|
|
|
|
$("#operazione").text(controllo["name"]);
|
|
|
|
|
|
|
|
// Avvio dei controlli
|
|
|
|
await avviaControllo(controllo);
|
|
|
|
}
|
|
|
|
|
|
|
|
setPercentage(100);
|
|
|
|
|
|
|
|
// Visualizzazione loader
|
|
|
|
loader.hide();
|
|
|
|
progress.hide();
|
|
|
|
|
|
|
|
// Messaggio informativo in caso di nessun problema
|
|
|
|
if ($("#controlli").html() === "") {
|
|
|
|
$("#no-problems").removeClass("hidden");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function(xhr) {
|
|
|
|
alert("'.tr('Errore').': " + xhr.responseJSON.error.message);
|
|
|
|
|
|
|
|
buttonRestore(button, restore);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-03-01 12:08:08 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param controllo
|
|
|
|
*/
|
2021-02-25 09:41:33 +01:00
|
|
|
function avviaControllo(controllo) {
|
|
|
|
return $.ajax({
|
|
|
|
url: globals.rootdir + "/actions.php",
|
|
|
|
type: "POST",
|
|
|
|
dataType: "JSON",
|
|
|
|
data: {
|
|
|
|
id_module: globals.id_module,
|
|
|
|
op: "controlli-check",
|
|
|
|
controllo: controllo["class"],
|
|
|
|
},
|
|
|
|
success: function(records) {
|
2021-03-01 12:08:08 +01:00
|
|
|
let success = false;
|
2021-02-25 09:41:33 +01:00
|
|
|
if (records.length === 0) {
|
2021-03-01 12:08:08 +01:00
|
|
|
success = true;
|
2021-02-25 09:41:33 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 12:08:08 +01:00
|
|
|
// Creazione pannello informativo e aggiunta righe
|
2024-05-16 18:02:50 +02:00
|
|
|
let card = initcard(controllo, success);
|
2021-02-25 09:41:33 +01:00
|
|
|
for(const record of records) {
|
2024-05-16 18:02:50 +02:00
|
|
|
addRiga(controllo, card, record);
|
2021-02-25 09:41:33 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 12:08:08 +01:00
|
|
|
// Visualizzazione delle informazioni
|
2024-05-16 18:02:50 +02:00
|
|
|
$("#controlli").append(card);
|
2021-02-25 09:41:33 +01:00
|
|
|
},
|
|
|
|
error: function(xhr, r, error) {
|
|
|
|
alert("'.tr('Errore').': " + error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-03-01 12:08:08 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param controllo
|
|
|
|
* @param records
|
|
|
|
* @param params
|
|
|
|
*/
|
2021-02-25 09:41:33 +01:00
|
|
|
function eseguiAzione(controllo, records, params) {
|
|
|
|
return $.ajax({
|
|
|
|
url: globals.rootdir + "/actions.php",
|
|
|
|
type: "POST",
|
|
|
|
dataType: "JSON",
|
|
|
|
data: {
|
|
|
|
id_module: globals.id_module,
|
|
|
|
op: "controlli-action",
|
|
|
|
controllo: controllo["class"],
|
|
|
|
records: records,
|
|
|
|
params: params,
|
|
|
|
},
|
|
|
|
success: function(results) {
|
|
|
|
$("#controllo-" + controllo["id"] + "-" + records.id).remove();
|
|
|
|
},
|
|
|
|
error: function(xhr, r, error) {
|
|
|
|
alert("'.tr('Errore').': " + error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-03-01 12:08:08 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param percent
|
|
|
|
*/
|
2021-02-25 09:41:33 +01:00
|
|
|
function setPercentage(percent) {
|
|
|
|
$("#progress .progress-bar").width(percent + "%");
|
|
|
|
$("#progress .progress-bar span").text(percent + "%");
|
|
|
|
}
|
|
|
|
|
2021-03-01 12:08:08 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param controllo
|
|
|
|
* @param success
|
|
|
|
* @returns {*|jQuery|HTMLElement}
|
|
|
|
*/
|
2024-05-16 18:02:50 +02:00
|
|
|
function initcard(controllo, success) {
|
2021-03-01 12:08:08 +01:00
|
|
|
let cssClass = "";
|
|
|
|
let icon = "minus";
|
|
|
|
if (success) {
|
2024-05-16 18:02:50 +02:00
|
|
|
cssClass = "card-success";
|
2021-03-01 12:08:08 +01:00
|
|
|
icon = "check text-success";
|
|
|
|
}
|
|
|
|
|
2024-05-16 18:02:50 +02:00
|
|
|
let card = `<div class="card ` + cssClass + `" id="controllo-` + controllo["id"] + `">
|
|
|
|
<div class="card-header with-border">
|
|
|
|
<h3 class="card-title">` + controllo["name"] + `</h3>
|
|
|
|
<div class="card-tools pull-right">
|
2024-05-23 17:51:21 +02:00
|
|
|
<button type="button" class="btn btn-tool" data-widget="collapse">
|
2021-03-01 12:08:08 +01:00
|
|
|
<i class="fa fa-` + icon + `"></i>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>`
|
|
|
|
|
|
|
|
if (!success) {
|
2024-05-16 18:02:50 +02:00
|
|
|
card += `
|
|
|
|
<div class="card-body">
|
2021-02-25 09:41:33 +01:00
|
|
|
<div class="table-responsive">
|
2024-10-16 15:48:50 +02:00
|
|
|
<table class="table table-striped table-hover table-sm table-bordered">
|
2021-02-25 09:41:33 +01:00
|
|
|
<thead>
|
|
|
|
<tr>
|
2021-03-01 14:46:13 +01:00
|
|
|
<th width="15%">'.tr('Record').'</th>
|
|
|
|
<th>'.tr('Descrizione').'</th>
|
|
|
|
<th class="text-center" width="15%">'.tr('Opzioni').'</th>
|
2021-02-25 09:41:33 +01:00
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody></tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
2021-03-01 12:08:08 +01:00
|
|
|
</div>`
|
|
|
|
}
|
|
|
|
|
2024-05-16 18:02:50 +02:00
|
|
|
card += `
|
2021-02-25 09:41:33 +01:00
|
|
|
</div>`;
|
|
|
|
|
2024-05-16 18:02:50 +02:00
|
|
|
return $(card);
|
2021-02-25 09:41:33 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 12:08:08 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param controllo
|
2024-05-16 18:02:50 +02:00
|
|
|
* @param card
|
2021-03-01 12:08:08 +01:00
|
|
|
* @param record
|
|
|
|
*/
|
2024-05-16 18:02:50 +02:00
|
|
|
function addRiga(controllo, card, record) {
|
|
|
|
let body = card.find("tbody");
|
2021-02-25 09:41:33 +01:00
|
|
|
|
|
|
|
// Generazione riga
|
2021-02-25 10:23:26 +01:00
|
|
|
let riga = `<tr class="` + record.type + `" id="controllo-` + controllo["id"] + `-` + record.id + `">
|
2021-02-25 09:41:33 +01:00
|
|
|
<td>` + record.nome + `</td>
|
|
|
|
<td>` + record.descrizione + `</td>
|
|
|
|
<td></td>
|
|
|
|
</tr>`;
|
|
|
|
riga = $(riga);
|
|
|
|
|
|
|
|
// Generazione opzioni
|
|
|
|
const options_columns = riga.find("td").last();
|
|
|
|
record.options.forEach(function (option, id){
|
|
|
|
let button = `<button type="button" class="btn btn-` + option.color + `">
|
|
|
|
<i class="` + option.icon + `"></i> ` + option.name + `
|
|
|
|
</buttton>`;
|
|
|
|
button = $(button);
|
|
|
|
|
|
|
|
button.on("click", function () {
|
|
|
|
option.params.id = id;
|
|
|
|
eseguiAzione(controllo, record, option.params);
|
|
|
|
});
|
|
|
|
|
|
|
|
options_columns.append(button);
|
|
|
|
});
|
|
|
|
|
|
|
|
body.append(riga);
|
|
|
|
}
|
|
|
|
</script>';
|