Aggiungi un singolo giorno o un intervallo: tutte le date nel periodo verranno escluse dalle lezioni.
Ciao , questi sono i giorni esclusi dalle lezioni.
getConnection(); function e($value): string { return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8'); } $idTeacher = 1; // TODO: legare all'insegnante loggato quando ce ne sarà più d'uno $message = $_GET['message'] ?? 'n'; $insertFeedback = null; /* ------------------------------------------------------------------------- * Inserimento dayoff (POST): singolo giorno o intervallo, con PRG * ---------------------------------------------------------------------- */ if (isset($_POST['submit']) || isset($_POST['submit_range'])) { $startRaw = trim($_POST['dayoff_start'] ?? ''); $endRaw = trim($_POST['dayoff_end'] ?? ''); $startTs = $startRaw !== '' ? strtotime($startRaw) : false; $endTs = $endRaw !== '' ? strtotime($endRaw) : $startTs; if ($startTs === false) { $insertFeedback = ['type' => 'error', 'text' => 'Inserisci almeno la data di inizio valida.']; } elseif ($endTs < $startTs) { $insertFeedback = ['type' => 'error', 'text' => 'La data di fine non può essere precedente a quella di inizio.']; } else { $daysSpan = (int) floor(($endTs - $startTs) / 86400) + 1; if ($daysSpan > 366) { $insertFeedback = ['type' => 'error', 'text' => 'L\'intervallo è troppo ampio (massimo un anno).']; } else { try { $pdo->beginTransaction(); $stmt = $pdo->prepare( "INSERT IGNORE INTO dayoff (idteacher, dayoffdate) VALUES (:idteacher, :dayoffdate)" ); $inserted = 0; $cursor = $startTs; while ($cursor <= $endTs) { $stmt->execute([':idteacher' => $idTeacher, ':dayoffdate' => date('Y-m-d', $cursor)]); $inserted += $stmt->rowCount(); $cursor = strtotime('+1 day', $cursor); } $pdo->commit(); header('Location: ' . $_SERVER['PHP_SELF'] . '?message=inserted&n=' . $inserted); exit; } catch (Throwable $ex) { if ($pdo->inTransaction()) { $pdo->rollBack(); } error_log('dayoff insert error: ' . $ex->getMessage()); $insertFeedback = ['type' => 'error', 'text' => 'Errore durante l\'inserimento. Riprova.']; } } } } /* ------------------------------------------------------------------------- * Elenco dayoff * ---------------------------------------------------------------------- */ $stmt = $pdo->prepare("SELECT iddayoff, dayoffdate FROM dayoff WHERE idteacher = :idteacher ORDER BY dayoffdate DESC"); $stmt->execute([':idteacher' => $idTeacher]); $documents = $stmt->fetchAll(); // Mappa data(Y-m-d) => iddayoff, passata al JS per la vista calendario $dayoffMap = []; foreach ($documents as $d) { $ts = strtotime($d['dayoffdate']); if ($ts) { $dayoffMap[date('Y-m-d', $ts)] = (int) $d['iddayoff']; } } $italianMonths = [ "January" => "Gennaio", "February" => "Febbraio", "March" => "Marzo", "April" => "Aprile", "May" => "Maggio", "June" => "Giugno", "July" => "Luglio", "August" => "Agosto", "September" => "Settembre", "October" => "Ottobre", "November" => "Novembre", "December" => "Dicembre" ]; $fmtDate = function ($d) use ($italianMonths) { $ts = strtotime($d); if (!$ts) return e($d); return date('d', $ts) . ' ' . $italianMonths[date('F', $ts)] . ' ' . date('Y', $ts); }; $insertedCount = isset($_GET['n']) ? (int) $_GET['n'] : null; ?>
Aggiungi un singolo giorno o un intervallo: tutte le date nel periodo verranno escluse dalle lezioni.
Ciao , questi sono i giorni esclusi dalle lezioni.