2022-10-06 17:08:18 +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';
|
2024-03-12 15:33:57 +01:00
|
|
|
use Models\Hook;
|
2022-10-06 17:08:18 +02:00
|
|
|
|
|
|
|
echo '
|
2024-10-16 15:48:50 +02:00
|
|
|
<table class="table table-hover table-sm">
|
2022-10-06 17:08:18 +02:00
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>'.tr('Nome').'</th>
|
2022-10-06 17:15:14 +02:00
|
|
|
<th class="text-center">'.tr('Ultima esecuzione').'</th>
|
|
|
|
<th class="text-center">'.tr('Stato').'</th>
|
2022-10-06 17:08:18 +02:00
|
|
|
</tr>
|
|
|
|
</thead>';
|
|
|
|
|
2024-03-05 16:01:45 +01:00
|
|
|
$hooks = $dbo->fetchArray('SELECT
|
|
|
|
`zz_hooks`.*,
|
2024-04-18 17:44:05 +02:00
|
|
|
`zz_modules_lang`.`title` AS modulo
|
2024-03-05 16:01:45 +01:00
|
|
|
FROM `zz_hooks`
|
2024-03-22 15:52:24 +01:00
|
|
|
LEFT JOIN `zz_hooks_lang` ON (`zz_hooks`.`id` = `zz_hooks_lang`.`id_record` AND `zz_hooks_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).')
|
2024-03-05 16:01:45 +01:00
|
|
|
INNER JOIN `zz_modules` ON `zz_hooks`.`id_module` = `zz_modules`.`id`
|
2024-03-22 15:52:24 +01:00
|
|
|
LEFT JOIN `zz_modules_lang` ON (`zz_modules`.`id` = `zz_modules_lang`.`id_record` AND `zz_modules_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).')
|
2024-03-05 16:01:45 +01:00
|
|
|
ORDER BY
|
|
|
|
`id_module` ASC, `zz_hooks`.`id` ASC');
|
2022-10-06 17:08:18 +02:00
|
|
|
|
|
|
|
$gruppi = collect($hooks)->groupBy('modulo');
|
|
|
|
foreach ($gruppi as $modulo => $hooks) {
|
|
|
|
echo '
|
|
|
|
<thead>
|
|
|
|
<tr>
|
2024-02-22 15:58:03 +01:00
|
|
|
<th colspan="4" class="text-center text-muted" >'.$modulo.'</th>
|
2022-10-06 17:08:18 +02:00
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
|
|
|
|
<tbody>';
|
|
|
|
|
|
|
|
foreach ($hooks as $hook) {
|
2024-03-12 15:33:57 +01:00
|
|
|
$hook = Hook::find($hook['id']);
|
|
|
|
$class = $hook->enabled ? 'success' : 'warning';
|
2022-10-06 17:08:18 +02:00
|
|
|
$nome_tipo = 'hook';
|
|
|
|
|
|
|
|
echo '
|
2024-09-09 09:28:48 +02:00
|
|
|
<tr class="'.$class.'" data-id="'.$hook->id.'" data-nome='.json_encode($hook->name).'>
|
2022-10-06 17:08:18 +02:00
|
|
|
<td>
|
2024-09-09 09:28:48 +02:00
|
|
|
'.$hook->name.(!empty($hook->help) ? '
|
2024-03-12 15:33:57 +01:00
|
|
|
<i class="tip fa fa-question-circle-o" title="'.$hook->help.'"</i>' : '').'
|
2022-10-06 17:08:18 +02:00
|
|
|
</td>
|
2022-10-06 17:15:14 +02:00
|
|
|
|
|
|
|
<td class="text-center">
|
2024-04-11 11:16:47 +02:00
|
|
|
'.(!empty($hook->processing_at) ? Translator::timestampToLocale($hook->processing_at) : '').'
|
2022-10-06 17:15:14 +02:00
|
|
|
</td>
|
|
|
|
|
2022-10-06 17:08:18 +02:00
|
|
|
<td class="text-center">';
|
|
|
|
|
|
|
|
// Possibilità di disabilitare o abilitare il hook
|
2024-03-12 15:33:57 +01:00
|
|
|
if ($hook->enabled) {
|
2022-10-06 17:08:18 +02:00
|
|
|
echo '
|
2024-05-16 18:02:50 +02:00
|
|
|
<div class="tip" data-widget="tooltip" title="'.tr('Questo _TYPE_ è abilitato: clicca qui per disabilitarlo', [
|
2024-03-22 15:52:24 +01:00
|
|
|
'_TYPE_' => $nome_tipo,
|
|
|
|
]).'">
|
2024-05-29 10:03:01 +02:00
|
|
|
<button type="button" class="btn btn-warning" onclick="disabilitaHook(this)">
|
2022-10-06 17:08:18 +02:00
|
|
|
<i class="fa fa-power-off" title="'.tr('Disabilita').'"></i>
|
|
|
|
</button>
|
|
|
|
</div>';
|
|
|
|
} else {
|
|
|
|
echo '
|
2024-05-16 18:02:50 +02:00
|
|
|
<div class="tip" data-widget="tooltip" title="'.tr('Questo _TYPE_ è disabilitato: clicca qui per abilitarlo', [
|
2024-03-22 15:52:24 +01:00
|
|
|
'_TYPE_' => $nome_tipo,
|
|
|
|
]).'">
|
2024-05-29 10:03:01 +02:00
|
|
|
<button type="button" class="btn btn-success" onclick="abilitaHook(this)">
|
2022-10-06 17:08:18 +02:00
|
|
|
<i class="fa fa-plug" title="'.tr('Abilita').'"></i>
|
|
|
|
</button>
|
|
|
|
</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
|
|
|
</td>
|
|
|
|
</tr>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-29 10:03:01 +02:00
|
|
|
echo '<tr><td colspan="3"><p> </p><button type="button" class="btn btn-danger pull-right" onclick="svuotaCacheHooks(this)">
|
2023-01-25 19:29:38 +01:00
|
|
|
<i class="fa fa-trash" title="'.tr('Svuota cache degli hooks').'"></i> '.tr('Svuota cache').'</button>
|
|
|
|
</td></tr>';
|
|
|
|
|
|
|
|
echo '
|
|
|
|
</tbody>';
|
|
|
|
|
2022-10-06 17:08:18 +02:00
|
|
|
echo '
|
|
|
|
</table>
|
|
|
|
|
|
|
|
<script>
|
2023-01-25 19:29:38 +01:00
|
|
|
|
|
|
|
function svuotaCacheHooks(button){
|
|
|
|
swal({
|
|
|
|
title: "'.tr('Svuota la cache degli hooks', []).'",
|
|
|
|
html: "'.tr('Sei sicuro di voler svuotare la cache degli hooks?', []).'",
|
|
|
|
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: "svuota-cache-hooks",
|
|
|
|
},
|
|
|
|
success: function (response) {
|
|
|
|
buttonRestore(button, restore);
|
|
|
|
renderMessages();
|
|
|
|
},
|
|
|
|
error: function() {
|
|
|
|
buttonRestore(button, restore);
|
|
|
|
swal({
|
|
|
|
type: "error",
|
|
|
|
title: globals.translations.ajax.error.title,
|
|
|
|
text: globals.translations.ajax.error.text,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
2022-10-06 17:08:18 +02:00
|
|
|
function disabilitaHook(button){
|
|
|
|
const riga = $(button).closest("tr");
|
|
|
|
const id = riga.data("id");
|
|
|
|
|
|
|
|
const nome = riga.data("nome");
|
|
|
|
const nome_tipo = "hook";
|
|
|
|
|
|
|
|
swal({
|
2023-01-25 19:29:38 +01:00
|
|
|
title: "'.tr('Disabilita _TYPE_', [
|
2024-03-22 15:52:24 +01:00
|
|
|
'_TYPE_' => '" + nome_tipo + "',
|
|
|
|
]).'",
|
2023-01-25 19:29:38 +01:00
|
|
|
html: "'.tr('Sei sicuro di voler disabilitare l\'_TYPE_ _NAME_?', [
|
2024-03-22 15:52:24 +01:00
|
|
|
'_TYPE_' => '" + nome_tipo + "',
|
|
|
|
'_NAME_' => '" + nome + "',
|
|
|
|
]).'",
|
2022-10-06 17:08:18 +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-hook",
|
|
|
|
id: id,
|
|
|
|
},
|
|
|
|
success: function (response) {
|
|
|
|
caricaElencoHooks();
|
|
|
|
renderMessages();
|
|
|
|
},
|
|
|
|
error: function() {
|
|
|
|
buttonRestore(button, restore);
|
|
|
|
|
|
|
|
swal({
|
|
|
|
type: "error",
|
|
|
|
title: globals.translations.ajax.error.title,
|
|
|
|
text: globals.translations.ajax.error.text,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function abilitaHook(button) {
|
|
|
|
const riga = $(button).closest("tr");
|
|
|
|
const id = riga.data("id");
|
|
|
|
|
|
|
|
const nome = riga.data("nome");
|
|
|
|
const nome_tipo = "hook";
|
|
|
|
|
|
|
|
swal({
|
2023-01-25 19:29:38 +01:00
|
|
|
title: "'.tr('Abilita _TYPE_', [
|
2024-03-22 15:52:24 +01:00
|
|
|
'_TYPE_' => '" + nome_tipo + "',
|
|
|
|
]).'",
|
2023-01-25 19:29:38 +01:00
|
|
|
html: "'.tr('Sei sicuro di voler abilitare l\'_TYPE_ _NAME_?', [
|
2024-03-22 15:52:24 +01:00
|
|
|
'_TYPE_' => '" + nome_tipo + "',
|
|
|
|
'_NAME_' => '" + nome + "',
|
|
|
|
]).'",
|
2022-10-06 17:08:18 +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-hook",
|
|
|
|
id: id,
|
|
|
|
},
|
|
|
|
success: function (response) {
|
|
|
|
caricaElencoHooks();
|
|
|
|
renderMessages();
|
|
|
|
},
|
|
|
|
error: function() {
|
|
|
|
buttonRestore(button, restore);
|
|
|
|
|
|
|
|
swal({
|
|
|
|
type: "error",
|
|
|
|
title: globals.translations.ajax.error.title,
|
|
|
|
text: globals.translations.ajax.error.text,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
</script>';
|