Non puoi selezionare più di 25 argomenti
Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
191 righe
5.9 KiB
191 righe
5.9 KiB
<?php |
|
define('_ELENCHI_API', 1); |
|
require_once(__DIR__ . "/inc/init.php"); |
|
|
|
if (!(isset($_SESSION["utente"]) && $_SESSION["utente"]->ruolo == "SAD")) { |
|
die_forbidden(); |
|
} |
|
|
|
|
|
// Per selezionare l'ente |
|
$codice_ente = intval($_REQUEST["codice_ente"] ?? ""); |
|
|
|
if(empty($codice_ente)) { |
|
die_forbidden(); |
|
} |
|
|
|
global $pdo; |
|
|
|
$info_ente = Ente::getInfoFromID($codice_ente); |
|
if($info_ente[0]["db"] != "S") { |
|
die_forbidden(); |
|
} |
|
|
|
$pdo->setConnessioneEnte($codice_ente); |
|
|
|
$endpoints = ElenchiAPI::getEndpoints(); |
|
|
|
|
|
if(!empty($_POST)) { |
|
$action = $_POST["action"] ?? ""; |
|
|
|
|
|
|
|
$success = false; |
|
$message = "Azione non consentita"; |
|
switch($action) { |
|
case "delete": |
|
$success = ElenchiAPI::deleteLocalEndpoint($_POST, $message); |
|
break; |
|
case "create": |
|
$success = ElenchiAPI::createLocalEndpoint($_POST, $message); |
|
break; |
|
} |
|
|
|
if($success) { |
|
?> |
|
swal({text:"Azione completata con successo",type:"success"}); |
|
<?php |
|
} else { |
|
?> |
|
swal({title:"Errore", text:`<?= $message ?>`,type:"error"}); |
|
<?php |
|
} |
|
die(); |
|
} |
|
?> |
|
|
|
<h3 class="mb-2"> |
|
<i class="fa fa-globe mr-2"></i> |
|
<?= count($endpoints["global"]) ?> endpoint globali (<code>config.json</code>) |
|
</h3> |
|
|
|
<?php foreach($endpoints["global"] as $key => $endpoint) : ?> |
|
<a <?= elenchi_api_href(url_with_params("/backend/elenchi_api/elenchi.php?endpoint={$key}&type=global"), $isModal) ?> |
|
class="btn my-1 status-border-primary btn-block btn-light text-left"> |
|
<ul class="px-3 py-1 m-0"> |
|
<li>key: <code><?= $key ?></code></li> |
|
<li>displayName: <code><?= $endpoint["displayName"] ?></code></li> |
|
<li>endpoint: <code><?= $endpoint["endpoint"] ?></code></li> |
|
</ul> |
|
</a> |
|
<?php endforeach; ?> |
|
|
|
<h3 class="mt-4 mb-2"> |
|
<i class="fa fa-network-wired mr-2"></i> |
|
<?= count($endpoints["local"]) ?> endpoint locali su ente <?= $codice_ente ?> |
|
</h3> |
|
|
|
<?php foreach($endpoints["local"] as $key => $endpoint) : ?> |
|
<div |
|
class="btn my-1 status-border-primary btn-block btn-light text-left"> |
|
<div class="row"> |
|
<div class="col col-8"> |
|
<ul class="px-3 py-1 m-0"> |
|
<li>key: <code><?= $key ?></code></li> |
|
<li>displayName: <code><?= $endpoint["displayName"] ?></code></li> |
|
<li>endpoint: <code><?= $endpoint["endpoint"] ?></code></li> |
|
</ul> |
|
</div> |
|
<div class="col col-4"> |
|
<button onclick="deleteLocal(`<?= $key ?>`)" class="btn btn-danger btn-sm float-right"> |
|
<i class="fa fa-trash"></i> |
|
</button> |
|
</div> |
|
</div> |
|
</div> |
|
<?php endforeach; ?> |
|
|
|
<h3 class="mt-4 mb-2"> |
|
<i class="fa fa-plus mr-2"></i> |
|
Aggiungi endpoint locale |
|
</h3> |
|
|
|
<form id="add_endpoint"> |
|
<div class="form-group mb-2"> |
|
<label for="displayName">displayName</label> |
|
<input class="form-control" id="__api_displayName" name="displayName" type="text"> |
|
</div> |
|
<div class="form-group mb-2"> |
|
<label for="endpoint">endpoint</label> |
|
<input class="form-control" id="__api_endpoint" name="endpoint" type="text"> |
|
</div> |
|
<div class="form-group"> |
|
<label for="token">token API</label> |
|
<input class="form-control" id="__api_token" name="token" type="text"> |
|
</div> |
|
<button onclick='createLocal(); event.preventDefault = true; return false;' id="create_albo_api" type="submit" class="btn btn-success btn-block"> |
|
<i class="fa fa-plus mr-1"></i> |
|
Aggiungi |
|
</button> |
|
</form> |
|
|
|
<script> |
|
<?php |
|
$postURL = "/backend/elenchi_api/manage.php"; |
|
$refeshURL = url_with_params($postURL); |
|
?> |
|
const postURL = `<?= $postURL ?>`; |
|
const refeshURL = `<?= $refeshURL ?>`; |
|
function deleteLocal(key) { |
|
Swal({ |
|
title: js_dict["sei-sicuro"], |
|
text: msg, |
|
type: "warning", |
|
showCancelButton: true, |
|
confirmButtonColor: '#3085d6', |
|
cancelButtonColor: '#d33', |
|
confirmButtonText: js_dict.conferma, |
|
cancelButtonText: js_dict.annulla, |
|
closeOnConfirm: true |
|
}).then((result) => { |
|
if (result.value) { |
|
let data = {}; |
|
data.modulo_riferimento = `<?= $modulo_riferimento ?>`; |
|
data.codice_ente = `<?= $codice_ente ?>`; |
|
data.action = 'delete'; |
|
data.key = key; |
|
$.ajax({ |
|
type: "POST", |
|
url: postURL, |
|
data: data, |
|
dataType: "script", |
|
success: function(result) { |
|
result; |
|
showModalWithURL(refeshURL); |
|
}, |
|
error: function() { |
|
swal(js_dict["error-retry"]); |
|
} |
|
}); |
|
} |
|
}); |
|
} |
|
function createLocal() { |
|
let data = {}; |
|
data.modulo_riferimento = `<?= $modulo_riferimento ?>`; |
|
data.action = 'create'; |
|
data.displayName = document.getElementById("__api_displayName").value; |
|
data.endpoint = document.getElementById("__api_endpoint").value; |
|
data.codice_ente = `<?= $codice_ente ?>`; |
|
data.token = document.getElementById("__api_token").value; |
|
$.ajax({ |
|
type: "POST", |
|
url: postURL, |
|
data: data, |
|
dataType: "script", |
|
success: function(result) { |
|
result; |
|
showModalWithURL(refeshURL); |
|
}, |
|
error: function() { |
|
swal(js_dict["error-retry"]); |
|
} |
|
}); |
|
} |
|
</script> |
|
|
|
|
|
<?php if(!$isModal) { |
|
include_once "{$beRoot}/layout/bottom.php"; |
|
} ?>
|