fixed finances my lesson etc

This commit is contained in:
2025-12-07 21:47:43 +01:00
parent 8c5b9a0d85
commit 70d01f160e
13 changed files with 2176 additions and 509 deletions
+227 -46
View File
@@ -843,12 +843,12 @@ $daily_sessions = $stmt->fetchAll();
<span class="fs-6">Situazione Clienti</span>
</a>
<!-- Pulsante Ordini -->
<a href="#" class="btn btn-success d-flex align-items-center px-3 py-2 shadow-sm rounded" style="min-width: 150px;">
<a href="orders.php" class="btn btn-success d-flex align-items-center px-3 py-2 shadow-sm rounded" style="min-width: 150px;">
<i class="bx bx-cart me-2" style="font-size: 20px;"></i>
<span class="fs-6">Ordini</span>
</a>
<!-- Pulsante Finanze -->
<a href="#" class="btn btn-warning d-flex align-items-center px-3 py-2 shadow-sm rounded" style="min-width: 150px;">
<a href="finances.php" class="btn btn-warning d-flex align-items-center px-3 py-2 shadow-sm rounded" style="min-width: 150px;">
<i class="bx bx-dollar me-2" style="font-size: 20px;"></i>
<span class="fs-6">Finanze</span>
</a>
@@ -867,7 +867,7 @@ $daily_sessions = $stmt->fetchAll();
<span class="fs-6">Giorni di Chiusura</span>
</a>
<!-- Pulsante Impostazioni -->
<a href="#" class="btn btn-dark d-flex align-items-center px-3 py-2 shadow-sm rounded" style="min-width: 150px;">
<a href="school_settings.php" class="btn btn-dark d-flex align-items-center px-3 py-2 shadow-sm rounded" style="min-width: 150px;">
<i class="bx bx-cog me-2" style="font-size: 20px;"></i>
<span class="fs-6">Impostazioni</span>
</a>
@@ -1076,73 +1076,126 @@ $daily_sessions = $stmt->fetchAll();
</div>
</div>
</div>
<!-- Sezione Sessioni della Giornata -->
<!-- Sezione Sessioni (Singolo giorno o Intervallo) -->
<div class="card radius-10 mb-4">
<div class="card-header">
<div class="d-flex align-items-center">
<div>
<h6 class="mb-0">Sessioni della Giornata</h6>
</div>
<div class="ms-auto">
<form action="" method="GET" class="d-flex align-items-center">
<label for="session_date" class="me-2">Seleziona Data:</label>
<input type="date" id="session_date" name="session_date" class="form-control" value="<?php echo htmlspecialchars($selected_date); ?>" onchange="this.form.submit()">
<div class="d-flex align-items-center justify-content-between">
<h6 class="mb-0">Sessioni Programmata</h6>
<div class="d-flex gap-2">
<!-- I tuoi filtri data esistenti -->
<form action="" method="GET" class="d-flex flex-wrap align-items-center gap-2">
<div class="d-flex align-items-center gap-2">
<label class="me-2 mb-0 text-nowrap">Dal:</label>
<input type="date" name="start_date" class="form-control form-control-sm" value="<?php echo $_GET['start_date'] ?? date('Y-m-d'); ?>" required>
</div>
<div class="d-flex align-items-center gap-2">
<label class="me-2 mb-0 text-nowrap">Al:</label>
<input type="date" name="end_date" class="form-control form-control-sm" value="<?php echo $_GET['end_date'] ?? ''; ?>">
</div>
<button type="submit" class="btn btn-primary btn-sm">Mostra</button>
<?php if (isset($_GET['start_date'])): ?>
<a href="?" class="btn btn-outline-secondary btn-sm">Oggi</a>
<?php endif; ?>
</form>
<!-- PULSANTE CALENDARIO -->
<button type="button" class="btn btn-success btn-sm" data-bs-toggle="modal" data-bs-target="#calendarModal">
<i class="bx bx-calendar"></i> Vista Calendario
</button>
</div>
</div>
</div>
<div class="card-body">
<?php
// Determina le date da mostrare
$start_date = $_GET['start_date'] ?? date('Y-m-d');
$end_date = $_GET['end_date'] ?? $start_date;
if ($end_date < $start_date) {
echo '<div class="alert alert-warning">La data di fine non può essere precedente alla data di inizio.</div>';
$end_date = $start_date;
}
// Recupera tutte le sessioni nell'intervallo
$stmt = $pdo->prepare("
SELECT cs.*,
ct.level, ct.day_of_week, ct.start_time, ct.room_name, ct.teacher_id,
c.name AS class_name, c.photo AS class_photo,
ct.photo AS variation_photo,
t.first_name AS teacher_first_name, t.last_name AS teacher_last_name
FROM class_sessions cs
JOIN class_types ct ON cs.class_type_id = ct.id
JOIN classes c ON ct.class_id = c.id
LEFT JOIN teachers t ON cs.teacher_id = t.id
WHERE cs.session_date BETWEEN ? AND ?
AND c.school_id = ?
ORDER BY cs.session_date, cs.start_time
");
$stmt->execute([$start_date, $end_date, $school_id]);
$range_sessions = $stmt->fetchAll();
?>
<div class="mb-3">
<strong>
<?php if ($start_date === $end_date): ?>
Sessioni del <span class="text-primary"><?php echo date('d/m/Y', strtotime($start_date)); ?></span>
<?php else: ?>
Sessioni dal <span class="text-primary"><?php echo date('d/m/Y', strtotime($start_date)); ?></span>
al <span class="text-primary"><?php echo date('d/m/Y', strtotime($end_date)); ?></span>
(<?php echo count($range_sessions); ?> totali)
<?php endif; ?>
</strong>
</div>
<div class="table-responsive">
<table id="dailySessionsTable" class="table table-striped table-bordered">
<thead>
<tr>
<th>Data</th>
<th>Classe</th>
<th>Variazione</th>
<th>Livello</th>
<th>Orario</th>
<th>Sala</th>
<th>Insegnante</th>
<th>Foto</th>
<th>Stato</th>
<th>Azioni</th>
</tr>
</thead>
<tbody>
<?php if (empty($daily_sessions)): ?>
<?php if (empty($range_sessions)): ?>
<tr>
<td colspan="8" class="text-center text-muted">Nessuna sessione trovata per questa data.</td>
<td colspan="8" class="text-center text-muted">
Nessuna sessione programmata in questo intervallo.
</td>
</tr>
<?php else: ?>
<?php foreach ($daily_sessions as $session): ?>
<?php
$current_date = '';
foreach ($range_sessions as $session):
$session_date = $session['session_date'];
if ($session_date !== $current_date):
$current_date = $session_date;
?>
<tr class="table-info">
<td colspan="8" class="fw-bold text-dark">
<?php echo date('d/m/Y (l)', strtotime($session_date)); ?>
</td>
</tr>
<?php endif; ?>
<tr>
<td><?php echo date('d/m', strtotime($session_date)); ?></td>
<td><?php echo htmlspecialchars($session['class_name']); ?></td>
<td><?php echo ucfirst($session['level']); ?></td>
<td><?php echo substr($session['start_time'], 0, 5); ?> - <?php echo substr($session['end_time'], 0, 5); ?></td>
<td><?php echo htmlspecialchars($session['room_name'] ?? '—'); ?></td>
<td>
<?php echo htmlspecialchars(ucfirst($session['level'])); ?>
(<?php echo htmlspecialchars(ucfirst($session['day_of_week'])); ?>)
<?php echo $session['teacher_id'] ? htmlspecialchars($session['teacher_first_name'] . ' ' . $session['teacher_last_name']) : '<em>Non assegnato</em>'; ?>
</td>
<td>
<?php echo htmlspecialchars($session['start_time']); ?> -
<?php echo htmlspecialchars($session['end_time']); ?>
</td>
<td><?php echo htmlspecialchars($session['room_name'] ?? 'Non specificata'); ?></td>
<td>
<?php if ($session['teacher_id']): ?>
<?php echo htmlspecialchars($session['teacher_first_name'] . ' ' . $session['teacher_last_name']); ?>
<?php else: ?>
Non assegnato
<?php endif; ?>
</td>
<td>
<?php
$photo = $session['variation_photo'] ?? $session['class_photo'];
if ($photo): ?>
<img src="<?php echo htmlspecialchars($photo); ?>" alt="Foto" style="max-width: 50px; max-height: 50px;">
<?php else: ?>
Nessuna foto
<?php endif; ?>
</td>
<td>
<span class="badge <?php echo $session['status'] === 'scheduled' ? 'bg-info' : ($session['status'] === 'completed' ? 'bg-success' : 'bg-danger'); ?>">
<?php echo htmlspecialchars(ucfirst($session['status'])); ?>
<span class="badge <?php
echo $session['status'] === 'scheduled' ? 'bg-info' : ($session['status'] === 'completed' ? 'bg-success' : 'bg-danger');
?>">
<?php echo $session['status'] === 'scheduled' ? 'Programmata' : ($session['status'] === 'completed' ? 'Completata' : 'Annullata'); ?>
</span>
</td>
<td>
@@ -1155,14 +1208,13 @@ $daily_sessions = $stmt->fetchAll();
"end_time" => $session['end_time'],
"teacher_id" => $session['teacher_id'],
"status" => $session['status']
]); ?>)'
data-bs-toggle="tooltip" data-bs-placement="top" title="Modifica">
]); ?>)'>
<i class="bx bx-edit"></i>
</button>
<form action="" method="POST" style="display:inline;" onsubmit="return confirm('Sei sicuro di voler eliminare questa sessione?');">
<form action="" method="POST" style="display:inline;" onsubmit="return confirm('Eliminare questa sessione?');">
<input type="hidden" name="action" value="delete_session">
<input type="hidden" name="id" value="<?php echo $session['id']; ?>">
<button type="submit" class="btn btn-sm btn-danger" data-bs-toggle="tooltip" data-bs-placement="top" title="Elimina">
<button type="submit" class="btn btn-sm btn-danger">
<i class="bx bx-trash"></i>
</button>
</form>
@@ -1682,6 +1734,135 @@ $daily_sessions = $stmt->fetchAll();
document.getElementById('edit_session_status').value = data.status;
}
</script>
<!-- MODALE CALENDARIO (GRANDE MA NON FULLSCREEN + FIXATO) -->
<div class="modal fade" id="calendarModal" tabindex="-1" aria-labelledby="calendarModalLabel" aria-hidden="true">
<div class="modal-dialog modal-xl modal-dialog-scrollable" style="max-width: 95vw;">
<div class="modal-content" style="height: 95vh;">
<div class="modal-header bg-primary text-white">
<h5 class="modal-title" id="calendarModalLabel">
Calendario Lezioni
</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body p-0 d-flex flex-column" style="height: 100%;">
<div id="fullcalendar-modal" class="flex-grow-1"></div>
</div>
</div>
</div>
</div>
<!-- FullCalendar CDN -->
<link href="https://cdn.jsdelivr.net/npm/fullcalendar@6.1.15/main.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/fullcalendar@6.1.15/main.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/fullcalendar@6.1.15/locales/it.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
let calendar = null;
const modalElement = document.getElementById('calendarModal');
const calendarEl = document.getElementById('fullcalendar-modal');
// Funzione per inizializzare o aggiornare il calendario
function initCalendar() {
if (calendar) {
calendar.destroy();
}
calendar = new FullCalendar.Calendar(calendarEl, {
locale: 'it',
initialView: 'timeGridWeek',
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek'
},
buttonText: {
today: 'Oggi',
month: 'Mese',
week: 'Settimana'
},
height: '100%',
slotMinTime: '06:00:00',
slotMaxTime: '23:00:00',
events: [
<?php
$from = date('Y-m-d');
$to = date('Y-m-d', strtotime('+90 days'));
$stmt = $pdo->prepare("
SELECT cs.session_date, cs.start_time, cs.end_time, cs.status,
c.name AS class_name, ct.level, ct.room_name,
t.first_name, t.last_name
FROM class_sessions cs
JOIN class_types ct ON cs.class_type_id = ct.id
JOIN classes c ON ct.class_id = c.id
LEFT JOIN teachers t ON cs.teacher_id = t.id
WHERE cs.session_date BETWEEN ? AND ?
AND c.school_id = ?
");
$stmt->execute([$from, $to, $school_id]);
foreach ($stmt->fetchAll() as $e) {
$title = $e['class_name'];
if ($e['level']) $title .= ' - ' . ucfirst($e['level']);
if ($e['first_name']) $title .= ' (' . $e['first_name'] . ')';
if ($e['room_name']) $title .= ' | ' . $e['room_name'];
$color = '#0d6efd';
if ($e['status'] === 'completed') $color = '#198754';
if ($e['status'] === 'cancelled') $color = '#dc3545';
echo "{
title: '" . addslashes($title) . "',
start: '{$e['session_date']}T{$e['start_time']}',
end: '{$e['session_date']}T{$e['end_time']}',
color: '$color'
}, ";
}
?>
],
eventClick: function(info) {
const date = info.event.start.toISOString().split('T')[0];
window.location.href = '?start_date=' + date + '&end_date=' + date;
}
});
calendar.render();
}
// Apri il modale → inizializza e forza resize
modalElement.addEventListener('shown.bs.modal', function() {
initCalendar();
setTimeout(() => calendar.updateSize(), 100);
});
// Se chiudi e riapri, ricarica
modalElement.addEventListener('hidden.bs.modal', function() {
if (calendar) {
calendar.destroy();
calendar = null;
}
});
});
</script>
<style>
#fullcalendar-modal .fc-header-toolbar {
margin-bottom: 15px;
}
#fullcalendar-modal .fc-button {
border-radius: 6px !important;
}
#fullcalendar-modal .fc-event {
border: none;
border-radius: 6px;
padding: 3px 6px;
font-size: 0.9em;
white-space: normal;
}
</style>
</body>
</html>