added statistic and remove froms school
This commit is contained in:
@@ -126,8 +126,18 @@ if ($school_id) {
|
||||
|
||||
if ($school) {
|
||||
$school_name = $school['name'];
|
||||
if (!empty($school['logo']) && file_exists("photoschool/" . $school['logo'])) {
|
||||
$school_logo_path = "photoschool/" . $school['logo'];
|
||||
$logoRaw = trim($school['logo'] ?? '');
|
||||
if (!empty($logoRaw)) {
|
||||
// Percorso fisico per verificare esistenza
|
||||
$physicalPath = __DIR__ . '/../' . $logoRaw; // da userarea/ sale a public/ + photoschool/...
|
||||
|
||||
if (file_exists($physicalPath)) {
|
||||
// Percorso web corretto (root-relative)
|
||||
$school_logo_path = '/' . $logoRaw;
|
||||
} else {
|
||||
// Debug: scrivi nel log se il file non esiste
|
||||
error_log("LOGO SCUOLA NON TROVATO - school_id: $school_id | path fisico: $physicalPath");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,6 +157,54 @@ $stmt = $pdo->prepare("
|
||||
$stmt->execute([$iduserlogin, $school_id]);
|
||||
$orders = $stmt->fetchAll();
|
||||
|
||||
// 1. Lezioni acquistate totali (somma total_entries da ordini completati)
|
||||
$stmt_total_lessons = $pdo->prepare("
|
||||
SELECT COALESCE(SUM(total_entries), 0) AS total_lessons
|
||||
FROM orders
|
||||
WHERE user_id = ? AND school_id = ? AND status = 'completed'
|
||||
");
|
||||
$stmt_total_lessons->execute([$iduserlogin, $school_id]);
|
||||
$total_lessons = $stmt_total_lessons->fetchColumn() ?: 0;
|
||||
|
||||
// 2. Lezioni da praticare (booked + data futura)
|
||||
$stmt_to_practice = $pdo->prepare("
|
||||
SELECT COUNT(sb.id) AS to_practice
|
||||
FROM session_bookings sb
|
||||
JOIN class_sessions cs ON sb.session_id = cs.id
|
||||
WHERE sb.user_id = ?
|
||||
AND cs.school_id = ?
|
||||
AND sb.status = 'booked'
|
||||
AND cs.session_date >= CURDATE()
|
||||
");
|
||||
$stmt_to_practice->execute([$iduserlogin, $school_id]);
|
||||
$to_practice = $stmt_to_practice->fetchColumn() ?: 0;
|
||||
|
||||
// 3. Lezioni perse (missed + data passata)
|
||||
$stmt_missed = $pdo->prepare("
|
||||
SELECT COUNT(sb.id) AS missed
|
||||
FROM session_bookings sb
|
||||
JOIN class_sessions cs ON sb.session_id = cs.id
|
||||
WHERE sb.user_id = ?
|
||||
AND cs.school_id = ?
|
||||
AND sb.status = 'missed'
|
||||
AND cs.session_date < CURDATE()
|
||||
");
|
||||
$stmt_missed->execute([$iduserlogin, $school_id]);
|
||||
$missed = $stmt_missed->fetchColumn() ?: 0;
|
||||
|
||||
// === CONTROLLA CERTIFICATI VALIDI ===
|
||||
$stmt_cert = $pdo->prepare("
|
||||
SELECT COUNT(*) AS valid_count
|
||||
FROM user_medical_certificates
|
||||
WHERE user_id = ?
|
||||
AND expiry_date IS NOT NULL
|
||||
AND expiry_date >= CURDATE()
|
||||
AND is_valid = 1
|
||||
");
|
||||
$stmt_cert->execute([$iduserlogin]);
|
||||
$cert_result = $stmt_cert->fetch(PDO::FETCH_ASSOC);
|
||||
$has_valid_cert = ($cert_result['valid_count'] > 0);
|
||||
|
||||
// === STATISTICHE RAPIDE ===
|
||||
$total_spent = array_sum(array_column($orders, 'price'));
|
||||
$total_entries = array_sum(array_column($orders, 'total_entries'));
|
||||
@@ -228,8 +286,9 @@ $active_orders = count(array_filter($orders, fn($o) => $o['status'] === 'complet
|
||||
<div class="card-body text-center py-5">
|
||||
|
||||
<!-- Logo solo se esiste -->
|
||||
<?php if ($school_logo_path): ?>
|
||||
<img src="<?php echo htmlspecialchars($school_logo_path); ?>"
|
||||
<?php
|
||||
if ($logoRaw): ?>
|
||||
<img src="<?php echo htmlspecialchars($logoRaw); ?>"
|
||||
alt="Logo <?php echo htmlspecialchars($school_name); ?>"
|
||||
class="mb-4 rounded-3 shadow"
|
||||
style="height: 90px; object-fit: contain;">
|
||||
@@ -256,42 +315,53 @@ $active_orders = count(array_filter($orders, fn($o) => $o['status'] === 'complet
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- PROFILO + STATISTICHE -->
|
||||
<?php if (!$has_valid_cert): ?>
|
||||
<div class="alert alert-danger alert-dismissible fade show mb-4 shadow" role="alert">
|
||||
<strong>Attenzione!</strong> Non hai un certificato medico valido caricato.
|
||||
<br>Ti potrebbe essere vietato l'accesso alle lezioni/pratiche.
|
||||
<a href="my_certificates.php" class="alert-link fw-bold ms-2">
|
||||
Caricalo subito qui →
|
||||
</a>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<!-- STATISTICHE PASTELLO - NUOVA VERSIONE -->
|
||||
<div class="row g-4 mb-5">
|
||||
<div class="col-lg-4">
|
||||
<div class="card stat-card text-center h-100">
|
||||
<div class="card-body">
|
||||
<img src="<?php echo $avatar; ?>" alt="Avatar" class="rounded-circle avatar-circle mb-3">
|
||||
<h5><?php echo htmlspecialchars($user['first_name'] . ' ' . $user['last_name']); ?></h5>
|
||||
<p class="text-muted"><?php echo htmlspecialchars($user['email']); ?></p>
|
||||
<!-- Box 1: Lezioni acquistate totali -->
|
||||
<div class="col-md-3">
|
||||
<div class="card stat-card text-center h-100" style="background: linear-gradient(135deg, #d1fae5, #a7f3d0);">
|
||||
<div class="card-body py-4">
|
||||
<h3 class="fw-bold text-success mb-1"><?= number_format($total_lessons) ?></h3>
|
||||
<p class="text-dark mb-0">Lezioni acquistate totali</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-8">
|
||||
<div class="row g-4">
|
||||
<div class="col-md-4">
|
||||
<div class="card stat-card text-center h-100">
|
||||
<div class="card-body">
|
||||
<h3 class="text-primary fw-bold"><?php echo count($orders); ?></h3>
|
||||
<p class="mb-0">Ordini totali</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Box 2: Lezioni da praticare -->
|
||||
<div class="col-md-3">
|
||||
<div class="card stat-card text-center h-100" style="background: linear-gradient(135deg, #dbeafe, #bfdbfe);">
|
||||
<div class="card-body py-4">
|
||||
<h3 class="fw-bold text-primary mb-1"><?= number_format($to_practice) ?></h3>
|
||||
<p class="text-dark mb-0">Lezioni da praticare</p>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="card stat-card text-center h-100">
|
||||
<div class="card-body">
|
||||
<h3 class="text-success fw-bold">€<?php echo number_format($total_spent, 2); ?></h3>
|
||||
<p class="mb-0">Speso in totale</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Box 3: Lezioni perse -->
|
||||
<div class="col-md-3">
|
||||
<div class="card stat-card text-center h-100" style="background: linear-gradient(135deg, #fee2e2, #fecaca);">
|
||||
<div class="card-body py-4">
|
||||
<h3 class="fw-bold text-danger mb-1"><?= number_format($missed) ?></h3>
|
||||
<p class="text-dark mb-0">Lezioni perse</p>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="card stat-card text-center h-100">
|
||||
<div class="card-body">
|
||||
<h3 class="text-info fw-bold"><?php echo $available_entries; ?></h3>
|
||||
<p class="mb-0">Ingressi disponibili</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Box 4: Vuoto (pronto per futuro) -->
|
||||
<div class="col-md-3">
|
||||
<div class="card stat-card text-center h-100" style="background: linear-gradient(135deg, #fef3c7, #fde68a);">
|
||||
<div class="card-body py-4 d-flex align-items-center justify-content-center">
|
||||
<p class="text-muted mb-0 fst-italic">Prossimamente...</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -370,6 +440,18 @@ $active_orders = count(array_filter($orders, fn($o) => $o['status'] === 'complet
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- PULSANTE RIMUOVI SCUOLA (in fondo, evidente) -->
|
||||
<!-- Link discreto per rimuoversi dalla scuola (in fondo a destra) -->
|
||||
<div class="text-end mt-5 mb-5 pe-4">
|
||||
<a href="#" class="text-danger small text-decoration-none"
|
||||
onclick="confirmRemoveSchool(<?= $school_id ?>, '<?= addslashes(htmlspecialchars($school_name)) ?>'); return false;">
|
||||
<i class="bx bx-log-out bx-sm me-1"></i>
|
||||
Rimuovimi da questa scuola
|
||||
</a>
|
||||
<p class="text-muted fst-italic small mt-1" style="font-size:0.8rem;">
|
||||
(azione irreversibile: perderai lezioni, crediti e storico associato)
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -377,6 +459,57 @@ $active_orders = count(array_filter($orders, fn($o) => $o['status'] === 'complet
|
||||
</div>
|
||||
|
||||
<?php include('jsinclude.php'); ?>
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
<script>
|
||||
const confirmRemoveSchool = (schoolId, schoolName) => {
|
||||
Swal.fire({
|
||||
title: `Abbandonare ${schoolName}?`,
|
||||
html: `Stai per rimuoverti completamente da <strong>${schoolName}</strong>.<br><br>` +
|
||||
`<strong class="text-danger">Attenzione:</strong> perderai irreversibilmente:<br>` +
|
||||
`<ul style="text-align:left; margin:15px 0 0 30px; font-size:0.95rem;">` +
|
||||
`<li>Tutte le tue lezioni prenotate</li>` +
|
||||
`<li>Crediti, ingressi e recuperi residui</li>` +
|
||||
`<li>Storico ordini e archivio personale legato a questa scuola</li>` +
|
||||
`</ul><br>` +
|
||||
`Questa azione <u>non può essere annullata</u>.`,
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#d33',
|
||||
cancelButtonColor: '#3085d6',
|
||||
confirmButtonText: 'Sì, rimuovimi definitivamente',
|
||||
cancelButtonText: 'No, mantienimi iscritto',
|
||||
reverseButtons: true
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
fetch('remove_school.php', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
body: 'school_id=' + schoolId
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
Swal.fire({
|
||||
title: 'Rimozione completata',
|
||||
text: `Non fai più parte di ${schoolName}.`,
|
||||
icon: 'success',
|
||||
timer: 3000
|
||||
}).then(() => {
|
||||
location.reload(); // o redirect a select_school.php
|
||||
});
|
||||
} else {
|
||||
Swal.fire('Errore', data.message || 'Impossibile rimuoverti dalla scuola.', 'error');
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
Swal.fire('Errore', 'Problema di connessione con il server.', 'error');
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
</script>
|
||||
<!-- Modal Cambia Scuola -->
|
||||
<div class="modal fade" id="changeSchoolModal" tabindex="-1">
|
||||
<div class="modal-dialog modal-lg">
|
||||
|
||||
Reference in New Issue
Block a user