Files
cmspro.it/app/views/calendar/index.php
2026-01-29 21:07:02 +01:00

201 lines
6.8 KiB
PHP

<?php
require_once __DIR__ . '/../layout.php';
$monthNames = [
1 => 'Styczeń', 2 => 'Luty', 3 => 'Marzec', 4 => 'Kwiecień',
5 => 'Maj', 6 => 'Czerwiec', 7 => 'Lipiec', 8 => 'Sierpień',
9 => 'Wrzesień', 10 => 'Październik', 11 => 'Listopad', 12 => 'Grudzień'
];
$dayNames = ['Pon', 'Wt', 'Śr', 'Czw', 'Pt', 'Sob', 'Ndz'];
// Obliczenia kalendarza
$firstDayOfMonth = mktime(0, 0, 0, $month, 1, $year);
$daysInMonth = cal_days_in_month(CAL_GREGORIAN, $month, $year);
$dayOfWeek = date('N', $firstDayOfMonth); // 1 = poniedziałek, 7 = niedziela
$prevMonth = $month - 1;
$prevYear = $year;
if ($prevMonth < 1) {
$prevMonth = 12;
$prevYear--;
}
$nextMonth = $month + 1;
$nextYear = $year;
if ($nextMonth > 12) {
$nextMonth = 1;
$nextYear++;
}
$today = date('Y-m-d');
ob_start();
?>
<?php if (isset($success)): ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<i class="bi bi-check-circle-fill me-2"></i>
<?= htmlspecialchars($success) ?>
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php endif; ?>
<?php if (isset($error)): ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<i class="bi bi-exclamation-triangle-fill me-2"></i>
<?= htmlspecialchars($error) ?>
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php endif; ?>
<div class="card">
<div class="card-header bg-transparent">
<div class="d-flex justify-content-between align-items-center">
<a href="/kalendarz?rok=<?= $prevYear ?>&miesiac=<?= $prevMonth ?>" class="btn btn-outline-primary">
<i class="bi bi-chevron-left"></i>
</a>
<h4 class="mb-0">
<i class="bi bi-calendar3 me-2"></i>
<?= $monthNames[$month] ?> <?= $year ?>
</h4>
<a href="/kalendarz?rok=<?= $nextYear ?>&miesiac=<?= $nextMonth ?>" class="btn btn-outline-primary">
<i class="bi bi-chevron-right"></i>
</a>
</div>
</div>
<div class="card-body p-0">
<table class="table table-bordered mb-0 calendar-table">
<thead>
<tr>
<?php foreach ($dayNames as $dayName): ?>
<th class="text-center py-2 bg-light"><?= $dayName ?></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php
$currentDay = 1;
$started = false;
for ($week = 0; $week < 6; $week++):
if ($currentDay > $daysInMonth) break;
?>
<tr>
<?php for ($dow = 1; $dow <= 7; $dow++):
$cellDate = null;
$isToday = false;
$hasEvents = false;
$dayEvents = [];
if (!$started && $dow == $dayOfWeek) {
$started = true;
}
if ($started && $currentDay <= $daysInMonth) {
$cellDate = sprintf('%04d-%02d-%02d', $year, $month, $currentDay);
$isToday = ($cellDate === $today);
$hasEvents = isset($eventsByDate[$cellDate]);
if ($hasEvents) {
$dayEvents = $eventsByDate[$cellDate];
}
$displayDay = $currentDay;
$currentDay++;
} else {
$displayDay = null;
}
?>
<td class="calendar-cell <?= $isToday ? 'today' : '' ?> <?= $hasEvents ? 'has-events' : '' ?>"
<?php if ($cellDate): ?>onclick="window.location='/kalendarz/dzien/<?= $cellDate ?>'"<?php endif; ?>>
<?php if ($displayDay): ?>
<div class="day-number <?= $isToday ? 'bg-primary text-white' : '' ?>">
<?= $displayDay ?>
</div>
<?php if ($hasEvents): ?>
<div class="day-events">
<?php foreach (array_slice($dayEvents, 0, 2) as $evt): ?>
<div class="event-dot" title="<?= htmlspecialchars($evt['title']) ?>">
<?= htmlspecialchars(mb_substr($evt['title'], 0, 15)) ?><?= mb_strlen($evt['title']) > 15 ? '...' : '' ?>
</div>
<?php endforeach; ?>
<?php if (count($dayEvents) > 2): ?>
<div class="event-more">+<?= count($dayEvents) - 2 ?> więcej</div>
<?php endif; ?>
</div>
<?php endif; ?>
<?php endif; ?>
</td>
<?php endfor; ?>
</tr>
<?php endfor; ?>
</tbody>
</table>
</div>
<div class="card-footer bg-transparent">
<div class="d-flex justify-content-between align-items-center">
<a href="/kalendarz?rok=<?= date('Y') ?>&miesiac=<?= date('m') ?>" class="btn btn-outline-secondary">
<i class="bi bi-calendar-check me-1"></i>Dzisiaj
</a>
<a href="/kalendarz/nowe" class="btn btn-primary">
<i class="bi bi-plus-lg me-1"></i>Nowe wydarzenie
</a>
</div>
</div>
</div>
<style>
.calendar-table {
table-layout: fixed;
}
.calendar-cell {
height: 100px;
vertical-align: top;
padding: 5px !important;
cursor: pointer;
transition: background-color 0.2s;
}
.calendar-cell:hover {
background-color: #f8f9fa;
}
.calendar-cell.today {
background-color: #e7f1ff;
}
.calendar-cell.has-events {
background-color: #fff3cd;
}
.calendar-cell.today.has-events {
background-color: #d1e7dd;
}
.day-number {
display: inline-block;
width: 28px;
height: 28px;
line-height: 28px;
text-align: center;
border-radius: 50%;
font-weight: 600;
margin-bottom: 3px;
}
.day-events {
font-size: 0.7rem;
}
.event-dot {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 1px 5px;
border-radius: 3px;
margin-bottom: 2px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.event-more {
color: #6c757d;
font-style: italic;
}
</style>
<?php
$content = ob_get_clean();
renderLayout('Kalendarz', $content, true, 'kalendarz', 'col-lg-10');