654 lines
30 KiB
PHP
654 lines
30 KiB
PHP
<?php
|
|
session_start();
|
|
include('include/headscript.php');
|
|
|
|
error_log("DASHBOARD HIT - user=" . ($_SESSION['iduserlogin'] ?? 'NOUSER') . " school=" . var_export($_SESSION['school_id'] ?? null, true));
|
|
|
|
if (!isset($iduserlogin)) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
$dbHandler = DBHandlerSelect::getInstance();
|
|
$pdo = $dbHandler->getConnection();
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| 1) Carico le scuole attive dell'utente
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
$stmt = $pdo->prepare("
|
|
SELECT
|
|
s.id,
|
|
s.name,
|
|
s.logo,
|
|
s.address_street,
|
|
s.address_city,
|
|
s.address_postal_code,
|
|
s.address_province,
|
|
s.address_country
|
|
FROM user_schools us
|
|
JOIN schools s ON us.school_id = s.id
|
|
WHERE us.user_id = ?
|
|
AND us.status = 'active'
|
|
AND s.status = 'active'
|
|
ORDER BY s.name
|
|
");
|
|
$stmt->execute([(int)$iduserlogin]);
|
|
$userSchools = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| 2) Cambio scuola da modale (POST)
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'change_school') {
|
|
$newSchoolId = (int)($_POST['school_id'] ?? 0);
|
|
|
|
$allowedIds = array_map(fn($r) => (int)$r['id'], $userSchools);
|
|
|
|
if ($newSchoolId > 0 && in_array($newSchoolId, $allowedIds, true)) {
|
|
// imposto sessione
|
|
$_SESSION['school_id'] = $newSchoolId;
|
|
|
|
// imposto anche il nome (comodo per UI)
|
|
foreach ($userSchools as $r) {
|
|
if ((int)$r['id'] === $newSchoolId) {
|
|
$_SESSION['school_name'] = $r['name'];
|
|
break;
|
|
}
|
|
}
|
|
|
|
// flag: selezione esplicita
|
|
$_SESSION['school_selected'] = 1;
|
|
|
|
header('Location: user_dashboard.php');
|
|
exit;
|
|
}
|
|
}
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| 3) Validazione school_id in sessione
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
$allowedIds = array_map(fn($r) => (int)$r['id'], $userSchools);
|
|
|
|
// Se l'utente non ha scuole -> vai alla select (dove vedrà le pubbliche)
|
|
if (count($userSchools) === 0) {
|
|
header('Location: select_school.php');
|
|
exit;
|
|
}
|
|
|
|
// Se school_id esiste ma NON appartiene all'utente -> reset
|
|
if (!empty($_SESSION['school_id']) && !in_array((int)$_SESSION['school_id'], $allowedIds, true)) {
|
|
unset($_SESSION['school_id'], $_SESSION['school_name'], $_SESSION['school_selected']);
|
|
}
|
|
|
|
// Caso: una sola scuola -> auto-select (OK)
|
|
if (count($userSchools) === 1 && empty($_SESSION['school_id'])) {
|
|
$_SESSION['school_id'] = (int)$userSchools[0]['id'];
|
|
$_SESSION['school_name'] = $userSchools[0]['name'];
|
|
$_SESSION['school_selected'] = 1;
|
|
echo $_SESSION['school_name'];
|
|
exit;
|
|
}
|
|
|
|
// Caso: più scuole -> OBBLIGO selezione esplicita
|
|
if (count($userSchools) > 1) {
|
|
if (empty($_SESSION['school_id']) || empty($_SESSION['school_selected'])) {
|
|
header('Location: select_school.php');
|
|
exit;
|
|
}
|
|
}
|
|
|
|
|
|
// === DATI UTENTE ===
|
|
$stmt = $pdo->prepare("SELECT first_name, last_name, email, avatar FROM auth_users WHERE id = ?");
|
|
$stmt->execute([$iduserlogin]);
|
|
$user = $stmt->fetch();
|
|
$avatar = $user['avatar'] ? '../upload/users/' . $user['avatar'] : '../assets/images/default-avatar.png';
|
|
|
|
// === SCUOLA CORRENTE ===
|
|
$school_id = (int)($_SESSION['school_id'] ?? 0);
|
|
|
|
if ($school_id <= 0) {
|
|
header('Location: select_school.php');
|
|
exit;
|
|
}
|
|
|
|
|
|
$school_name = 'Nessuna scuola selezionata';
|
|
$school_logo_path = null; // niente default
|
|
|
|
if ($school_id) {
|
|
$stmt = $pdo->prepare("SELECT name, logo FROM schools WHERE id = ?");
|
|
$stmt->execute([$school_id]);
|
|
$school = $stmt->fetch();
|
|
|
|
if ($school) {
|
|
$school_name = $school['name'];
|
|
$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");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// === ORDINI UTENTE ===
|
|
$stmt = $pdo->prepare("
|
|
SELECT o.*, p.name AS product_name, pv.name AS variation_name,
|
|
c.name AS class_name, ct.level, ct.day_of_week
|
|
FROM orders o
|
|
JOIN products p ON o.product_id = p.id
|
|
LEFT JOIN product_variations pv ON o.variation_id = pv.id
|
|
LEFT JOIN classes c ON o.class_id = c.id
|
|
LEFT JOIN class_types ct ON o.class_type_id = ct.id
|
|
WHERE o.user_id = ? AND o.school_id = ?
|
|
ORDER BY o.created_at DESC
|
|
");
|
|
$stmt->execute([$iduserlogin, $school_id]);
|
|
$orders = $stmt->fetchAll();
|
|
|
|
// Lezioni ACQUISTATE totali
|
|
$stmt_acquistate = $pdo->prepare("
|
|
SELECT COALESCE(SUM(total_entries), 0) AS acquistate
|
|
FROM orders
|
|
WHERE user_id = ? AND school_id = ? AND status = 'completed'
|
|
");
|
|
$stmt_acquistate->execute([$iduserlogin, $school_id]);
|
|
$acquistate = (int) $stmt_acquistate->fetchColumn();
|
|
|
|
// Da PRATICARE (booked future)
|
|
$stmt_da_praticare = $pdo->prepare("
|
|
SELECT COUNT(sb.id) AS da_praticare
|
|
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_da_praticare->execute([$iduserlogin, $school_id]);
|
|
$da_praticare = (int) $stmt_da_praticare->fetchColumn();
|
|
|
|
// PRATICATE (attended + booked passate)
|
|
$stmt_praticate = $pdo->prepare("
|
|
SELECT COUNT(sb.id) AS praticate
|
|
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 = 'attended'
|
|
OR (sb.status = 'booked' AND cs.session_date < CURDATE())
|
|
)
|
|
");
|
|
$stmt_praticate->execute([$iduserlogin, $school_id]);
|
|
$praticate = (int) $stmt_praticate->fetchColumn();
|
|
|
|
// PERSE (missed + data passata)
|
|
$stmt_perse = $pdo->prepare("
|
|
SELECT COUNT(sb.id) AS perse
|
|
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_perse->execute([$iduserlogin, $school_id]);
|
|
$perse = (int) $stmt_perse->fetchColumn();
|
|
|
|
// DA PROGRAMMARE (residuo = acquistate - perse - praticate - da_praticare)
|
|
$da_programmare = max(0, $acquistate - $perse - $praticate - $da_praticare);;
|
|
|
|
// === 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'));
|
|
$available_entries = array_sum(array_column($orders, 'available_entries'));
|
|
$active_orders = count(array_filter($orders, fn($o) => $o['status'] === 'completed' && (!$o['expiration_date'] || strtotime($o['expiration_date']) >= time())));
|
|
?>
|
|
|
|
<!doctype html>
|
|
<html lang="it">
|
|
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>La mia Dashboard - Yogiboook</title>
|
|
<?php include('cssinclude.php'); ?>
|
|
<?php include('siteinfo.php'); ?>
|
|
<style>
|
|
:root {
|
|
--pastel-blue: #94bacc;
|
|
--pastel-green: #a3d9b1;
|
|
--pastel-pink: #f8bbd0;
|
|
--pastel-yellow: #fff8c4;
|
|
}
|
|
|
|
.card-pastel {
|
|
background: linear-gradient(135deg, #94bacc, #a3d9b1);
|
|
color: white;
|
|
}
|
|
|
|
.card-soft {
|
|
background: #ffffff;
|
|
border: 1px solid #e0e0e0;
|
|
}
|
|
|
|
.stat-card {
|
|
background: white;
|
|
border-radius: 15px;
|
|
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.stat-card:hover {
|
|
transform: translateY(-5px);
|
|
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
|
|
}
|
|
|
|
.avatar-circle {
|
|
width: 100px;
|
|
height: 100px;
|
|
object-fit: cover;
|
|
border: 4px solid white;
|
|
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
|
|
}
|
|
|
|
.table-pastel thead {
|
|
background-color: var(--pastel-blue);
|
|
color: white;
|
|
}
|
|
|
|
.badge-soft {
|
|
padding: 0.4em 0.8em;
|
|
border-radius: 50px;
|
|
font-size: 0.85rem;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="wrapper">
|
|
<?php include('include/navbar.php'); ?>
|
|
<?php include('include/topbar.php'); ?>
|
|
|
|
<div class="page-wrapper">
|
|
<div class="page-content" style="background: linear-gradient(to bottom, #f0f8ff, #f8f9fa); min-height: 100vh;">
|
|
|
|
<!-- SCUOLA + BENVENUTO -->
|
|
<div class="container-fluid px-4 pt-4">
|
|
<div class="card card-pastel radius-20 shadow-lg mb-4 position-relative">
|
|
<div class="card-body text-center py-5">
|
|
|
|
<!-- Logo solo se esiste -->
|
|
<?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;">
|
|
<?php endif; ?>
|
|
|
|
<!-- Saluto -->
|
|
<h2 class="mb-2 text-white">
|
|
Ciao<?php echo $user['first_name'] ? ', ' . htmlspecialchars($user['first_name']) : ''; ?>!
|
|
</h2>
|
|
<p class="mb-0 fs-4 text-white opacity-90">
|
|
Sei nella scuola: <strong><?php echo htmlspecialchars($school_name); ?></strong>
|
|
</p>
|
|
|
|
<!-- PULSANTI IN RIGA (uno accanto all'altro) -->
|
|
<div class="position-absolute top-0 end-0 mt-3 me-3 d-flex gap-2">
|
|
<a href="my_lessons.php" class="btn btn-light btn-lg shadow-sm px-4">
|
|
<i class="bx bx-calendar-heart me-2"></i>Le mie lezioni
|
|
</a>
|
|
<button type="button" class="btn btn-outline-light btn-lg shadow-sm px-4"
|
|
data-bs-toggle="modal" data-bs-target="#changeSchoolModal">
|
|
<i class="bx bx-transfer me-2"></i>Cambia scuola
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?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 - 5 BOX CHE OCCUPANO TUTTA LA RIGA SU DESKTOP -->
|
|
<div class="row g-3 mb-5">
|
|
<!-- 1. Lezioni acquistate -->
|
|
<div class="col-6 col-sm-4 col-md">
|
|
<div class="card stat-card text-center h-100 shadow-sm" style="background: linear-gradient(135deg, #d1fae5, #a7f3d0); border: none;">
|
|
<div class="card-body py-4 px-3">
|
|
<h4 class="fw-bold text-success mb-1"><?= number_format($acquistate) ?></h4>
|
|
<p class="text-dark mb-0 small">Acquistate</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 2. Praticate -->
|
|
<div class="col-6 col-sm-4 col-md">
|
|
<div class="card stat-card text-center h-100 shadow-sm" style="background: linear-gradient(135deg, #e0f2fe, #bae6fd); border: none;">
|
|
<div class="card-body py-4 px-3">
|
|
<h4 class="fw-bold text-info mb-1"><?= number_format($praticate) ?></h4>
|
|
<p class="text-dark mb-0 small">Praticate</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 3. Da praticare -->
|
|
<div class="col-6 col-sm-4 col-md">
|
|
<div class="card stat-card text-center h-100 shadow-sm" style="background: linear-gradient(135deg, #dbeafe, #bfdbfe); border: none;">
|
|
<div class="card-body py-4 px-3">
|
|
<h4 class="fw-bold text-primary mb-1"><?= number_format($da_praticare) ?></h4>
|
|
<p class="text-dark mb-0 small">Da praticare</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 4. Perse -->
|
|
<div class="col-6 col-sm-4 col-md">
|
|
<div class="card stat-card text-center h-100 shadow-sm" style="background: linear-gradient(135deg, #fee2e2, #fecaca); border: none;">
|
|
<div class="card-body py-4 px-3">
|
|
<h4 class="fw-bold text-danger mb-1"><?= number_format($perse) ?></h4>
|
|
<p class="text-dark mb-0 small">Perse</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 5. Da programmare -->
|
|
<div class="col-6 col-sm-4 col-md">
|
|
<div class="card stat-card text-center h-100 shadow-sm" style="background: linear-gradient(135deg, #fef3c7, #fde68a); border: none;">
|
|
<div class="card-body py-4 px-3">
|
|
<h4 class="fw-bold text-warning mb-1"><?= number_format($da_programmare) ?></h4>
|
|
<p class="text-dark mb-0 small">Da programmare</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- I TUOI ORDINI -->
|
|
<div class="card radius-20 shadow-lg">
|
|
<div class="card-header bg-primary text-white d-flex justify-content-between align-items-center">
|
|
<h4 class="mb-0">I tuoi ordini</h4>
|
|
<span class="badge bg-light text-dark"><?php echo count($orders); ?> totali</span>
|
|
</div>
|
|
<div class="card-body p-0">
|
|
<?php if (empty($orders)): ?>
|
|
<div class="text-center py-5">
|
|
<i class="bx bx-package bx-lg text-muted"></i>
|
|
<h5 class="text-muted mt-3">Non hai ancora effettuato ordini</h5>
|
|
<a href="products.php" class="btn btn-primary mt-3">Vai ai corsi</a>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="table-responsive">
|
|
<table class="table table-hover align-middle mb-0">
|
|
<thead class="table-pastel">
|
|
<tr>
|
|
<th>Data</th>
|
|
<th>Ordine</th>
|
|
<th>Prodotto</th>
|
|
<th>Ingressi</th>
|
|
<th>Scadenza</th>
|
|
<th>Prezzo</th>
|
|
<th>Stato</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($orders as $o): ?>
|
|
<tr class="table-light">
|
|
<td><?php echo date('d/m/Y', strtotime($o['created_at'])); ?></td>
|
|
<td><strong>#<?php echo $o['order_number']; ?></strong></td>
|
|
<td>
|
|
<strong><?php echo htmlspecialchars($o['product_name']); ?></strong>
|
|
<?php if ($o['variation_name']): ?>
|
|
<br><small class="text-success"><?php echo htmlspecialchars($o['variation_name']); ?></small>
|
|
<?php endif; ?>
|
|
<?php if ($o['class_name']): ?>
|
|
<br><small class="text-info"><?php echo htmlspecialchars($o['class_name']); ?></small>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td>
|
|
<?php if ($o['available_entries'] != $o['total_entries']): ?>
|
|
<span class="text-success"><?php echo $o['available_entries']; ?></span>/<?php echo $o['total_entries']; ?>
|
|
<?php else: ?>
|
|
<?php echo $o['total_entries']; ?>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td>
|
|
<?php if ($o['expiration_date']): ?>
|
|
<span class="<?php echo strtotime($o['expiration_date']) < time() ? 'text-danger' : 'text-warning'; ?>">
|
|
<?php echo date('d/m/Y', strtotime($o['expiration_date'])); ?>
|
|
</span>
|
|
<?php else: ?>
|
|
<em>Nessuna</em>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td class="text-success fw-bold">€<?php echo number_format($o['price'], 2); ?></td>
|
|
<td>
|
|
<span class="badge-soft <?php echo $o['status'] == 'completed' ? 'bg-success' : ($o['status'] == 'pending' ? 'bg-warning' : 'bg-secondary'); ?>">
|
|
<?php echo ucfirst($o['status']); ?>
|
|
</span>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</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>
|
|
|
|
<?php include('include/footer.php'); ?>
|
|
</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">
|
|
<div class="modal-content">
|
|
<div class="modal-header bg-primary text-white">
|
|
<h5 class="modal-title">Scegli la scuola</h5>
|
|
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<?php if (empty($userSchools)): ?>
|
|
<div class="text-center text-muted py-4">
|
|
Nessuna scuola associata.
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="row g-3">
|
|
<?php foreach ($userSchools as $s): ?>
|
|
<?php
|
|
$sid = (int)$s['id'];
|
|
$sname = $s['name'];
|
|
$logoPath = null;
|
|
$logoRaw = trim((string)($s['logo'] ?? ''));
|
|
|
|
if ($logoRaw !== '') {
|
|
// se in DB è già "photoschool/xxx.jpg" lo uso così com'è
|
|
$logoRel = ltrim($logoRaw, '/');
|
|
|
|
// check file su disco (stessa cartella di questo file)
|
|
$disk1 = __DIR__ . '/' . $logoRel;
|
|
$disk2 = __DIR__ . '/../' . $logoRel;
|
|
|
|
if (is_file($disk1)) {
|
|
$logoPath = $logoRel;
|
|
} elseif (is_file($disk2)) {
|
|
$logoPath = '../' . $logoRel;
|
|
} else {
|
|
// fallback web
|
|
$logoPath = $logoRel;
|
|
}
|
|
}
|
|
|
|
$isCurrent = ($sid === (int)$school_id);
|
|
?>
|
|
<div class="col-md-6">
|
|
<div class="card shadow-sm h-100">
|
|
<div class="card-body d-flex align-items-center gap-3">
|
|
<?php if ($logoPath): ?>
|
|
<img src="<?= htmlspecialchars($logoPath) ?>" style="height:50px;width:auto;" class="rounded" onerror="this.style.display='none';">
|
|
<?php else: ?>
|
|
<i class="bx bx-building-house bx-md text-muted"></i>
|
|
<?php endif; ?>
|
|
|
|
<div class="flex-grow-1">
|
|
<div class="fw-bold"><?= htmlspecialchars($sname) ?></div>
|
|
<?php
|
|
$addrParts = [];
|
|
|
|
if (!empty($s['address_street'])) {
|
|
$addrParts[] = $s['address_street'];
|
|
}
|
|
|
|
$cityLine = trim(
|
|
($s['address_postal_code'] ?? '') . ' ' .
|
|
($s['address_city'] ?? '') .
|
|
(!empty($s['address_province']) ? ' (' . $s['address_province'] . ')' : '')
|
|
);
|
|
|
|
if ($cityLine !== '') {
|
|
$addrParts[] = $cityLine;
|
|
}
|
|
|
|
if (!empty($s['address_country'])) {
|
|
$addrParts[] = $s['address_country'];
|
|
}
|
|
|
|
$fullAddress = implode(', ', array_map('trim', $addrParts));
|
|
?>
|
|
|
|
<?php if ($fullAddress !== ''): ?>
|
|
<div class="text-muted small">
|
|
<i class="bx bx-map me-1"></i><?= htmlspecialchars($fullAddress) ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($isCurrent): ?>
|
|
<div class="text-success small">Selezionata</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<?php if (!$isCurrent): ?>
|
|
<form method="POST" class="m-0">
|
|
<input type="hidden" name="action" value="change_school">
|
|
<input type="hidden" name="school_id" value="<?= $sid ?>">
|
|
<button type="submit" class="btn btn-primary">
|
|
Seleziona
|
|
</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
|
|
</html>
|