tetraq/public/report.html

312 lines
15 KiB
HTML
Raw Normal View History

2026-03-15 17:00:01 +01:00
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Report Statistiche TetraQ</title>
<script defer src="/__/firebase/10.8.0/firebase-app-compat.js"></script>
<script defer src="/__/firebase/10.8.0/firebase-firestore-compat.js"></script>
<script defer src="/__/firebase/init.js"></script>
<style>
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: #f4f7f6; color: #333; padding: 20px; margin: 0; box-sizing: border-box;}
/* STILI LOGIN */
#login-view { background-color: #34495e; position: fixed; top: 0; left: 0; width: 100%; height: 100vh; display: flex; justify-content: center; align-items: center; z-index: 1000; padding: 20px; box-sizing: border-box; }
.login-box { background: white; padding: 40px; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.2); text-align: center; width: 100%; max-width: 350px; box-sizing: border-box; }
.login-box h2 { color: #2c3e50; margin-top: 0; }
.login-box input[type="text"], .login-box input[type="password"] { width: 100%; padding: 12px; margin: 10px 0 20px 0; border: 1px solid #bdc3c7; border-radius: 5px; box-sizing: border-box; font-size: 16px; }
.login-box button { width: 100%; background-color: #3498db; color: white; border: none; padding: 12px; font-size: 16px; border-radius: 5px; cursor: pointer; font-weight: bold; transition: 0.2s; }
.login-box button:hover { background-color: #2980b9; }
.error { color: #e74c3c; font-weight: bold; font-size: 14px; margin-top: -5px; margin-bottom: 15px; }
/* STILI DASHBOARD */
#dashboard-view { display: none; }
.container { max-width: 1200px; margin: 0 auto; background: white; padding: 30px; border-radius: 10px; box-shadow: 0 4px 8px rgba(0,0,0,0.1); box-sizing: border-box;}
.header-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
h1 { color: #2c3e50; margin: 0; font-size: 24px;}
.btn-logout { background-color: #e74c3c; color: white; padding: 8px 15px; border-radius: 5px; text-decoration: none; font-weight: bold; font-size: 14px; white-space: nowrap; border: none; cursor: pointer;}
.btn-logout:hover { background-color: #c0392b; }
.filter-section { background: #eef2f5; padding: 20px; border-radius: 8px; margin-bottom: 30px; display: flex; flex-wrap: wrap; gap: 15px; align-items: flex-end; }
.form-group { display: flex; flex-direction: column; flex: 1; min-width: 150px; }
.form-group label { font-size: 13px; font-weight: bold; color: #34495e; margin-bottom: 5px; }
.form-group input, .form-group select { padding: 10px; border: 1px solid #bdc3c7; border-radius: 5px; font-size: 14px; outline: none; box-sizing: border-box; width: 100%;}
.form-group input:focus, .form-group select:focus { border-color: #3498db; }
.btn-filtra { background-color: #3498db; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; font-weight: bold; font-size: 14px; transition: 0.2s; height: 40px; }
.btn-filtra:hover { background-color: #2980b9; }
.btn-reset { background-color: #95a5a6; color: white; padding: 10px 15px; border: none; border-radius: 5px; cursor: pointer; text-decoration: none; font-size: 14px; height: 40px; line-height: 20px; box-sizing: border-box; display: inline-block; text-align: center;}
.dashboard { display: flex; justify-content: space-between; margin-bottom: 30px; gap: 20px; text-align: center; flex-wrap: wrap; }
.card { flex: 1; min-width: 150px; background: #ecf0f1; padding: 20px; border-radius: 8px; border-left: 5px solid #3498db; box-sizing: border-box;}
.card.ios { border-left-color: #e74c3c; }
.card.android { border-left-color: #2ecc71; }
.card h3 { margin: 0 0 10px 0; font-size: 14px; color: #7f8c8d; text-transform: uppercase; }
.card p { margin: 0; font-size: 28px; font-weight: bold; color: #2c3e50; }
table { width: 100%; border-collapse: collapse; margin-top: 20px; font-size: 14px; table-layout: fixed; }
th, td { padding: 12px 15px; text-align: left; border-bottom: 1px solid #ddd; word-wrap: break-word;}
th { background-color: #34495e; color: white; }
tr:hover { background-color: #f1f1f1; }
/* Larghezze specifiche per evitare colonne deformate */
th:nth-child(1) { width: 15%; }
th:nth-child(2) { width: 25%; }
th:nth-child(3) { width: 15%; }
th:nth-child(4) { width: 20%; }
th:nth-child(5) { width: 25%; }
.badge { padding: 4px 8px; border-radius: 4px; color: white; font-weight: bold; font-size: 12px; }
.badge-ios { background-color: #e74c3c; }
.badge-android { background-color: #2ecc71; }
.badge-desktop { background-color: #95a5a6; }
.empty { text-align: center; padding: 30px; color: #7f8c8d; font-style: italic; background: #f9f9f9; border-radius: 5px;}
/* MOBILE */
@media (max-width: 768px) {
body { padding: 10px; }
.container { padding: 15px; }
.header-top { flex-direction: column; text-align: center; gap: 15px; }
.filter-section { flex-direction: column; align-items: stretch; gap: 10px; padding: 15px;}
.form-group { min-width: 100%; }
.btn-filtra, .btn-reset { width: 100%; margin-top: 5px; height: auto; padding: 12px;}
.dashboard { flex-direction: column; gap: 15px; }
.card { min-width: 100%; }
table, thead, tbody, th, td, tr { display: block; width: 100%; box-sizing: border-box; }
thead { display: none; }
tr { margin-bottom: 15px; border: 1px solid #ddd; border-radius: 8px; overflow: hidden; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,0.05); }
td { display: flex; flex-direction: column; text-align: left; border-bottom: 1px solid #eee; padding: 12px 15px; position: relative; width: 100%; }
td::before { content: attr(data-label); font-weight: bold; margin-bottom: 5px; color: #34495e; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
td:last-child { border-bottom: none; }
}
</style>
</head>
<body>
<div id="login-view">
<div class="login-box">
<h2>Area Riservata</h2>
<div id="login-error" class="error"></div>
<form id="login-form">
<input type="text" id="username" name="username" placeholder="Nome Utente (io)" autocomplete="username" required>
<input type="password" id="password" name="password" placeholder="Inserisci la password" autocomplete="current-password" required>
<button type="submit">Accedi</button>
</form>
</div>
</div>
<div id="dashboard-view">
<div class="container">
<div class="header-top">
<h1>📊 Report Statistiche TetraQ</h1>
<button class="btn-logout" onclick="logout()">Esci 🚪</button>
</div>
<form class="filter-section" id="filter-form">
<div class="form-group">
<label for="data_da">Data Da:</label>
<input type="date" id="data_da">
</div>
<div class="form-group">
<label for="data_a">Data A:</label>
<input type="date" id="data_a">
</div>
<div class="form-group">
<label for="os">Sistema Operativo:</label>
<select id="os">
<option value="">Tutti i sistemi</option>
<option value="iOS">Apple iOS</option>
<option value="Android">Google Android</option>
<option value="Desktop">Desktop (Mac/Win)</option>
</select>
</div>
<div class="form-group">
<label for="loc">Località (es. Roma):</label>
<input type="text" id="loc" placeholder="Cerca città...">
</div>
<button type="submit" class="btn-filtra">🔍 Applica Filtri</button>
<button type="button" class="btn-reset" onclick="resetFilters()">✖ Reset</button>
</form>
<div class="dashboard">
<div class="card">
<h3>Giocatori Trovati</h3>
<p id="totale-text">0</p>
</div>
<div class="card ios">
<h3>Apple iOS</h3>
<p id="ios-text">0</p>
</div>
<div class="card android">
<h3>Google Android</h3>
<p id="android-text">0</p>
</div>
<div class="card">
<h3>Desktop / Altro</h3>
<p id="desktop-text">0</p>
</div>
</div>
<h2>Dettaglio Giocatori</h2>
<table>
<thead>
<tr>
<th>Ultimo Accesso</th>
<th>Giocatore (Livello)</th>
<th>Sistema</th>
<th>Località (IP)</th>
<th>Dispositivo Hardware</th>
</tr>
</thead>
<tbody id="table-body">
<tr><td colspan="5" class="empty">Caricamento dati dal database...</td></tr>
</tbody>
</table>
</div>
</div>
<script>
const PASSWORD_SEGRETA = "!!TetraQ!!"; // La tua password sicura
const UTENTE_SEGRETO = "io"; // Il nome utente richiesto
let allData = [];
// GESTIONE LOGIN
document.getElementById('login-form').addEventListener('submit', function(e) {
e.preventDefault();
const user = document.getElementById('username').value.trim().toLowerCase();
const pwd = document.getElementById('password').value;
if (user === UTENTE_SEGRETO && pwd === PASSWORD_SEGRETA) {
document.getElementById('login-view').style.display = 'none';
document.getElementById('dashboard-view').style.display = 'block';
loadFirebaseData();
} else {
document.getElementById('login-error').innerText = "Credenziali errate! Riprova.";
}
});
function logout() {
document.getElementById('password').value = '';
document.getElementById('login-error').innerText = '';
document.getElementById('dashboard-view').style.display = 'none';
document.getElementById('login-view').style.display = 'flex';
document.getElementById('table-body').innerHTML = '<tr><td colspan="5" class="empty">Caricamento dati dal database...</td></tr>';
allData = [];
}
// CONNESSIONE A FIREBASE E RECUPERO DATI
function loadFirebaseData() {
const db = firebase.firestore();
db.collection('leaderboard').orderBy('lastActive', 'desc').get().then((snapshot) => {
allData = [];
snapshot.forEach(doc => {
let data = doc.data();
if (data.lastActive) {
data.dateObj = data.lastActive.toDate();
data.dateStr = data.dateObj.toISOString().substring(0, 10);
} else {
data.dateStr = "2000-01-01";
}
allData.push(data);
});
applyFilters();
}).catch(error => {
console.error("Errore lettura database:", error);
document.getElementById('table-body').innerHTML = '<tr><td colspan="5" class="empty" style="color:red;">Errore di connessione a Firebase.</td></tr>';
});
}
// GESTIONE FILTRI
document.getElementById('filter-form').addEventListener('submit', function(e) {
e.preventDefault();
applyFilters();
});
function resetFilters() {
document.getElementById('data_da').value = '';
document.getElementById('data_a').value = '';
document.getElementById('os').value = '';
document.getElementById('loc').value = '';
applyFilters();
}
function applyFilters() {
const fDa = document.getElementById('data_da').value;
const fA = document.getElementById('data_a').value;
const fOs = document.getElementById('os').value;
const fLoc = document.getElementById('loc').value.toLowerCase();
let tot = 0, ios = 0, android = 0, desktop = 0;
let html = '';
allData.forEach(row => {
let mostra = true;
let platform = row.platform || 'Sconosciuta';
let city = (row.city || '').toLowerCase();
let ip = row.ip || 'N/D';
let name = row.name || 'Sconosciuto';
let level = row.level || 1;
let device = row.deviceModel || 'N/D';
let appVersion = row.appVersion || 'N/D';
// Formattazione data precisa e sicura
let dateDisplay = row.dateObj ? row.dateObj.toLocaleString('it-IT', {
year: 'numeric', month: 'short', day: '2-digit',
hour: '2-digit', minute: '2-digit', hour12: false
}) : 'N/D';
// Filtro Data Da
if (fDa !== '' && row.dateStr < fDa) mostra = false;
// Filtro Data A
if (fA !== '' && row.dateStr > fA) mostra = false;
// Filtro Sistema Operativo
if (fOs !== '') {
if (fOs === 'Desktop' && (platform === 'iOS' || platform === 'Android')) mostra = false;
if (fOs !== 'Desktop' && platform !== fOs) mostra = false;
}
// Filtro Località
if (fLoc !== '' && !city.includes(fLoc)) mostra = false;
if (mostra) {
tot++;
let badgeClass = 'badge-desktop';
let platformDisplay = platform;
if (platform === 'iOS') { ios++; badgeClass = 'badge-ios'; }
else if (platform === 'Android') { android++; badgeClass = 'badge-android'; }
else { desktop++; platformDisplay = 'Desktop'; }
html += `
<tr>
<td data-label="Ultimo Accesso">${dateDisplay}</td>
<td data-label="Giocatore">
<strong>${name}</strong> (Liv. ${level})<br>
<small style="color:#7f8c8d;">App v. ${appVersion}</small>
</td>
<td data-label="Sistema"><span class="badge ${badgeClass}">${platformDisplay}</span></td>
<td data-label="Località">
${row.city || 'N/D'}<br>
<small style="color:#7f8c8d;">IP: ${ip}</small>
</td>
<td data-label="Dispositivo Hardware" style="font-size: 12px; color: #7f8c8d;">${device}</td>
</tr>
`;
}
});
if (tot === 0) {
html = '<tr><td colspan="5" class="empty">Nessun giocatore corrisponde ai filtri selezionati.</td></tr>';
}
// Aggiorna la vista
document.getElementById('table-body').innerHTML = html;
document.getElementById('totale-text').innerText = tot;
document.getElementById('ios-text').innerText = ios;
document.getElementById('android-text').innerText = android;
document.getElementById('desktop-text').innerText = desktop;
}
</script>
</body>
</html>