211 lines
7.4 KiB
PHP
211 lines
7.4 KiB
PHP
<?php
|
|
// Questo file può essere vuoto o contenere logica PHP aggiuntiva se necessario
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="it">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Autenticazione VisualLims</title>
|
|
<!-- Includi Select2 CSS -->
|
|
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
max-width: 600px;
|
|
margin: 20px auto;
|
|
padding: 20px;
|
|
}
|
|
|
|
#authButton {
|
|
padding: 10px 20px;
|
|
background-color: #007bff;
|
|
color: white;
|
|
border: none;
|
|
cursor: pointer;
|
|
}
|
|
|
|
#authButton:hover {
|
|
background-color: #0056b3;
|
|
}
|
|
|
|
#result {
|
|
margin-top: 20px;
|
|
padding: 10px;
|
|
border: 1px solid #ccc;
|
|
word-wrap: break-word;
|
|
}
|
|
|
|
#schemiResult {
|
|
margin-top: 20px;
|
|
padding: 10px;
|
|
border: 1px solid #ccc;
|
|
word-wrap: break-word;
|
|
}
|
|
|
|
.select2-container {
|
|
width: 100% !important;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<h1>Autenticazione VisualLims</h1>
|
|
<button id="authButton">Autentica</button>
|
|
<div id="result"></div>
|
|
|
|
<!-- Tendina per i clienti -->
|
|
<h3>Seleziona un cliente:</h3>
|
|
<select id="clientiSelect" style="width: 100%;">
|
|
<option value="">Seleziona un cliente...</option>
|
|
</select>
|
|
|
|
<!-- Area per mostrare gli schemi -->
|
|
<div id="schemiResult"></div>
|
|
|
|
<!-- Includi jQuery (necessario per Select2) -->
|
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
|
<!-- Includi Select2 JS -->
|
|
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
|
|
|
|
<script>
|
|
// Inizializza Select2 sulla tendina
|
|
$(document).ready(function() {
|
|
$('#clientiSelect').select2({
|
|
placeholder: "Cerca un cliente...",
|
|
allowClear: true
|
|
});
|
|
|
|
// Carica i clienti al caricamento della pagina
|
|
loadClienti();
|
|
});
|
|
|
|
// Autenticazione
|
|
document.getElementById('authButton').addEventListener('click', async () => {
|
|
const resultDiv = document.getElementById('result');
|
|
resultDiv.textContent = 'Autenticazione in corso...';
|
|
|
|
try {
|
|
const response = await fetch('auth_proxy.php', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
}
|
|
});
|
|
|
|
const data = await response.json();
|
|
if (!response.ok) {
|
|
throw new Error(`Errore HTTP! Stato: ${response.status}, Dettagli: ${data.error || 'Nessun dettaglio disponibile'}`);
|
|
}
|
|
|
|
if (typeof data === 'string' && data.length > 0) {
|
|
resultDiv.textContent = `Token: ${data}`;
|
|
} else if (data && data.token) {
|
|
resultDiv.textContent = `Token: ${data.token}`;
|
|
} else {
|
|
resultDiv.textContent = `Autenticazione fallita: Nessun token ricevuto. Dettagli: ${JSON.stringify(data)}`;
|
|
}
|
|
} catch (error) {
|
|
resultDiv.textContent = `Errore: ${error.message}`;
|
|
}
|
|
});
|
|
|
|
// Funzione per caricare i clienti nella tendina
|
|
async function loadClienti() {
|
|
const resultDiv = document.getElementById('result');
|
|
resultDiv.textContent = 'Caricamento clienti...';
|
|
|
|
try {
|
|
const response = await fetch('get_clienti.php', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({})
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (!response.ok) {
|
|
throw new Error(data.error || `Errore HTTP: ${response.status}, Dettagli: ${JSON.stringify(data)}`);
|
|
}
|
|
|
|
if (data.value && Array.isArray(data.value)) {
|
|
const select = document.getElementById('clientiSelect');
|
|
data.value.forEach(c => {
|
|
const nome = c.Nominativo || 'Nome non disponibile';
|
|
const id = c.IdCliente || 'ID non disponibile';
|
|
const option = new Option(`${nome.trim()} (ID: ${id})`, id);
|
|
select.add(option);
|
|
});
|
|
resultDiv.textContent = 'Clienti caricati con successo.';
|
|
} else {
|
|
resultDiv.textContent = 'Nessun cliente trovato o formato dati non valido.';
|
|
console.log('Risposta API:', data);
|
|
}
|
|
} catch (err) {
|
|
resultDiv.textContent = 'Errore: ' + err.message;
|
|
console.error('Dettagli errore:', err);
|
|
}
|
|
}
|
|
|
|
// Evento per gestire la selezione di un cliente e recuperare gli schemi
|
|
$('#clientiSelect').on('select2:select', async function(e) {
|
|
const clienteId = e.target.value; // Oppure: $(this).val()
|
|
const schemiDiv = document.getElementById('schemiResult'); // Correzione del nome variabile
|
|
|
|
// Log per debug
|
|
console.log('Cliente selezionato:', clienteId);
|
|
|
|
if (!clienteId) {
|
|
schemiDiv.textContent = '';
|
|
return;
|
|
}
|
|
|
|
schemiDiv.textContent = 'Caricamento schemi...';
|
|
|
|
try {
|
|
const response = await fetch('get_schemi.php', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
clienteId
|
|
})
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (!response.ok) {
|
|
throw new Error(data.error || `Errore HTTP: ${response.status}, Dettagli: ${JSON.stringify(data)}`);
|
|
}
|
|
|
|
if (data.SchemiAbilitati && Array.isArray(data.SchemiAbilitati)) {
|
|
let html = '<h3>Schemi Abilitati:</h3><ul>';
|
|
data.SchemiAbilitati.forEach(s => {
|
|
const nomeSchema = s.NomeSchema || s.Descrizione || 'Schema non specificato';
|
|
html += `<li>${nomeSchema}</li>`;
|
|
});
|
|
html += '</ul>';
|
|
schemiDiv.innerHTML = html;
|
|
} else {
|
|
schemiDiv.textContent = 'Nessuno schema trovato per questo cliente.';
|
|
console.log('Risposta Schemi:', data);
|
|
}
|
|
} catch (err) {
|
|
schemiDiv.textContent = 'Errore: ' + err.message;
|
|
console.error('Dettagli errore:', err);
|
|
}
|
|
});
|
|
|
|
// Gestisci la deselezione (opzionale)
|
|
$('#clientiSelect').on('select2:unselect', function(e) {
|
|
const schemiDiv = document.getElementById('schemiResult'); // Correzione del nome variabile
|
|
schemiDiv.textContent = '';
|
|
});
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|