blob: eddc230d80b39aded8eb75173fd7daee6bc45dd2 [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001<?php
2class calendarsView {
3 public static function renderCalendar($current, $ends, $selectedFunc, $disabled = false, $extra = false) {
4 $interval = new DateInterval("P1D");
5
6 echo '<div class="overflow-wrapper">';
7
8 $start = true;
9 $day = 0;
10 while ($current->diff($ends)->invert === 0) {
11 $dow = (int)$current->format("w");
12 if ($dow == 0) $dow = 7;
13 $dom = (int)$current->format("d");
14
15 if ($dow == 1) echo "</tr>";
16 if ($dom == 1) echo "</table>";
17 if ($dom == 1 || $start) echo "<div class='month'>".security::htmlsafe(ucfirst(strftime("%B %G", $current->getTimestamp())))."</div><table class='calendar'>";
18 if ($dow == 1 || $start) echo "<tr>";
19 if ($dom == 1 || $start) {
20 for ($i = 1; $i < $dow; $i++) {
21 echo "<td></td>";
22 }
23 }
24
25 echo "<td class='day'><span class='date'>".$dom."</span><br><select name='type[$day]'".($disabled ? " disabled" : "").">";
26
27 foreach (calendars::$types as $id => $type) {
28 echo "<option value='".(int)$id."'".($selectedFunc($current->getTimestamp(), $id, $dow, $dom, $extra) ? " selected" : "").">".security::htmlsafe($type)."</option>";
29 }
30
31 echo "</td>";
32
33 $start = false;
34 $day++;
35 $current->add($interval);
36 }
37
38 for ($i = $dow + 1; $i <= 7; $i++) {
39 echo "<td></td>";
40 }
41
42 echo "</tr></table></div>";
43 }
44}