added class sessione and propagate and day off
This commit is contained in:
@@ -0,0 +1,318 @@
|
||||
<?php
|
||||
// Forza la visualizzazione degli errori
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
include('include/headscript.php');
|
||||
|
||||
// Connessione al database
|
||||
$dbHandler = DBHandlerSelect::getInstance();
|
||||
$pdo = $dbHandler->getConnection();
|
||||
|
||||
// Verifica che iduserlogin sia definito
|
||||
if (!isset($iduserlogin)) {
|
||||
die("Errore: ID utente non definito.");
|
||||
}
|
||||
|
||||
// Recupera i dati della scuola in base all'utente loggato
|
||||
$stmt = $pdo->prepare("SELECT id, name FROM schools WHERE owner_id = ?");
|
||||
$stmt->execute([$iduserlogin]);
|
||||
$school = $stmt->fetch();
|
||||
if (!$school) {
|
||||
die("Errore: Nessuna scuola trovata per l'utente loggato.");
|
||||
}
|
||||
$school_id = $school['id'];
|
||||
$school_name = $school['name'];
|
||||
|
||||
// Gestione delle azioni (aggiunta, modifica, cancellazione)
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if (isset($_POST['action'])) {
|
||||
$action = $_POST['action'];
|
||||
|
||||
// Aggiunta di un giorno di chiusura
|
||||
if ($action === 'add') {
|
||||
$start_date = $_POST['start_date'] ?? '';
|
||||
$end_date = $_POST['end_date'] ?? '';
|
||||
$description = $_POST['description'] ?? null;
|
||||
|
||||
// Validazione: assicurarsi che end_date >= start_date
|
||||
if (empty($start_date) || empty($end_date)) {
|
||||
$error = "Le date di inizio e fine sono obbligatorie.";
|
||||
} elseif (strtotime($end_date) < strtotime($start_date)) {
|
||||
$error = "La data di fine non può essere precedente alla data di inizio.";
|
||||
} else {
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO day_off (school_id, start_date, end_date, description)
|
||||
VALUES (?, ?, ?, ?)
|
||||
");
|
||||
$success = $stmt->execute([
|
||||
$school_id,
|
||||
$start_date,
|
||||
$end_date,
|
||||
$description
|
||||
]);
|
||||
|
||||
if ($success) {
|
||||
$success_message = "Giorno di chiusura aggiunto con successo!";
|
||||
} else {
|
||||
$error = "Errore durante l'aggiunta del giorno di chiusura.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Modifica di un giorno di chiusura
|
||||
if ($action === 'edit') {
|
||||
$id = $_POST['id'] ?? 0;
|
||||
$start_date = $_POST['start_date'] ?? '';
|
||||
$end_date = $_POST['end_date'] ?? '';
|
||||
$description = $_POST['description'] ?? null;
|
||||
|
||||
// Validazione: assicurarsi che end_date >= start_date
|
||||
if (empty($start_date) || empty($end_date)) {
|
||||
$error = "Le date di inizio e fine sono obbligatorie.";
|
||||
} elseif (strtotime($end_date) < strtotime($start_date)) {
|
||||
$error = "La data di fine non può essere precedente alla data di inizio.";
|
||||
} else {
|
||||
$stmt = $pdo->prepare("
|
||||
UPDATE day_off
|
||||
SET start_date = ?, end_date = ?, description = ?
|
||||
WHERE id = ? AND school_id = ?
|
||||
");
|
||||
$success = $stmt->execute([
|
||||
$start_date,
|
||||
$end_date,
|
||||
$description,
|
||||
$id,
|
||||
$school_id
|
||||
]);
|
||||
|
||||
if ($success) {
|
||||
$success_message = "Giorno di chiusura aggiornato con successo!";
|
||||
} else {
|
||||
$error = "Errore durante l'aggiornamento del giorno di chiusura.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cancellazione di un giorno di chiusura
|
||||
if ($action === 'delete') {
|
||||
$id = $_POST['id'] ?? 0;
|
||||
$stmt = $pdo->prepare("DELETE FROM day_off WHERE id = ? AND school_id = ?");
|
||||
$success = $stmt->execute([$id, $school_id]);
|
||||
|
||||
if ($success) {
|
||||
$success_message = "Giorno di chiusura eliminato con successo!";
|
||||
} else {
|
||||
$error = "Errore durante l'eliminazione del giorno di chiusura.";
|
||||
}
|
||||
}
|
||||
|
||||
// Reindirizza per evitare il doppio invio del form
|
||||
header("Location: day_off.php");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// Recupera tutti i giorni di chiusura della scuola
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT *
|
||||
FROM day_off
|
||||
WHERE school_id = ?
|
||||
ORDER BY start_date
|
||||
");
|
||||
$stmt->execute([$school_id]);
|
||||
$days_off = $stmt->fetchAll();
|
||||
?>
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<!-- Required meta tags -->
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<!--favicon-->
|
||||
<link rel="icon" href="assets/images/favicon-32x32.png" type="image/png" />
|
||||
<?php include('cssinclude.php'); ?>
|
||||
<?php include('siteinfo.php'); ?>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<!--wrapper-->
|
||||
<div class="wrapper">
|
||||
<!--sidebar wrapper -->
|
||||
<?php include('include/navbar.php'); ?>
|
||||
<!--end sidebar wrapper -->
|
||||
<!--start header -->
|
||||
<?php include('include/topbar.php'); ?>
|
||||
<!--end header -->
|
||||
<!--start page wrapper -->
|
||||
<div class="page-wrapper">
|
||||
<div class="page-content">
|
||||
<div class="card radius-10">
|
||||
<div class="card-header">
|
||||
<div class="d-flex align-items-center">
|
||||
<div>
|
||||
<h6 class="mb-0">Giorni di Chiusura - <?php echo htmlspecialchars($school_name); ?></h6>
|
||||
</div>
|
||||
<div class="ms-auto">
|
||||
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addDayOffModal">
|
||||
Aggiungi Giorno di Chiusura
|
||||
</button>
|
||||
<a href="school_dashboard.php" class="btn btn-secondary ms-2">Torna alla Dashboard</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (isset($success_message)): ?>
|
||||
<div class="alert alert-success" role="alert">
|
||||
<?php echo $success_message; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($error)): ?>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<?php echo $error; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="table-responsive">
|
||||
<table id="daysOffTable" class="table table-striped table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Data Inizio</th>
|
||||
<th>Data Fine</th>
|
||||
<th>Descrizione</th>
|
||||
<th>Azioni</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($days_off as $day_off): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($day_off['start_date']); ?></td>
|
||||
<td><?php echo htmlspecialchars($day_off['end_date']); ?></td>
|
||||
<td><?php echo htmlspecialchars($day_off['description'] ?? ''); ?></td>
|
||||
<td>
|
||||
<button type="button" class="btn btn-sm btn-warning" data-bs-toggle="modal" data-bs-target="#editDayOffModal"
|
||||
onclick='fillEditDayOffModal(<?php echo json_encode([
|
||||
"id" => $day_off['id'],
|
||||
"start_date" => $day_off['start_date'],
|
||||
"end_date" => $day_off['end_date'],
|
||||
"description" => htmlspecialchars($day_off['description'] ?? '', ENT_QUOTES)
|
||||
]); ?>)'>
|
||||
Modifica
|
||||
</button>
|
||||
<form action="" method="POST" style="display:inline;" onsubmit="return confirm('Sei sicuro di voler eliminare questo giorno di chiusura?');">
|
||||
<input type="hidden" name="action" value="delete">
|
||||
<input type="hidden" name="id" value="<?php echo $day_off['id']; ?>">
|
||||
<button type="submit" class="btn btn-sm btn-danger">Elimina</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--end page wrapper -->
|
||||
<!--start overlay-->
|
||||
<div class="overlay toggle-icon"></div>
|
||||
<!--end overlay-->
|
||||
<!--Start Back To Top Button-->
|
||||
<a href="javaScript:;" class="back-to-top"><i class='bx bxs-up-arrow-alt'></i></a>
|
||||
<!--End Back To Top Button-->
|
||||
<?php include('include/footer.php'); ?>
|
||||
</div>
|
||||
<!--end wrapper-->
|
||||
|
||||
<!-- Modale per aggiungere un giorno di chiusura -->
|
||||
<div class="modal fade" id="addDayOffModal" tabindex="-1" aria-labelledby="addDayOffModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="addDayOffModalLabel">Aggiungi Giorno di Chiusura</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<form action="" method="POST">
|
||||
<div class="modal-body">
|
||||
<input type="hidden" name="action" value="add">
|
||||
<div class="mb-3">
|
||||
<label for="add_day_off_start_date" class="form-label">Data Inizio</label>
|
||||
<input type="date" class="form-control" id="add_day_off_start_date" name="start_date" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="add_day_off_end_date" class="form-label">Data Fine</label>
|
||||
<input type="date" class="form-control" id="add_day_off_end_date" name="end_date" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="add_day_off_description" class="form-label">Descrizione</label>
|
||||
<input type="text" class="form-control" id="add_day_off_description" name="description" placeholder="Es. Natale">
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Chiudi</button>
|
||||
<button type="submit" class="btn btn-primary">Aggiungi</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modale per modificare un giorno di chiusura -->
|
||||
<div class="modal fade" id="editDayOffModal" tabindex="-1" aria-labelledby="editDayOffModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="editDayOffModalLabel">Modifica Giorno di Chiusura</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<form action="" method="POST">
|
||||
<div class="modal-body">
|
||||
<input type="hidden" name="action" value="edit">
|
||||
<input type="hidden" name="id" id="edit_day_off_id">
|
||||
<div class="mb-3">
|
||||
<label for="edit_day_off_start_date" class="form-label">Data Inizio</label>
|
||||
<input type="date" class="form-control" id="edit_day_off_start_date" name="start_date" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="edit_day_off_end_date" class="form-label">Data Fine</label>
|
||||
<input type="date" class="form-control" id="edit_day_off_end_date" name="end_date" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="edit_day_off_description" class="form-label">Descrizione</label>
|
||||
<input type="text" class="form-control" id="edit_day_off_description" name="description" placeholder="Es. Natale">
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Chiudi</button>
|
||||
<button type="submit" class="btn btn-primary">Salva Modifiche</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include('jsinclude.php'); ?>
|
||||
|
||||
<!-- Script per inizializzare DataTables e gestire i modali -->
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#daysOffTable').DataTable({
|
||||
"language": {
|
||||
"url": "//cdn.datatables.net/plug-ins/1.10.25/i18n/Italian.json"
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function fillEditDayOffModal(data) {
|
||||
document.getElementById('edit_day_off_id').value = data.id;
|
||||
document.getElementById('edit_day_off_start_date').value = data.start_date;
|
||||
document.getElementById('edit_day_off_end_date').value = data.end_date;
|
||||
document.getElementById('edit_day_off_description').value = data.description;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user