-
Notifications
You must be signed in to change notification settings - Fork 0
/
calendar.php
87 lines (82 loc) · 3.41 KB
/
calendar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Календарь - Әфишка</title>
<link rel="stylesheet" href="./css/styles.css">
</head>
<body>
<?php
class Calendar {
private $active_year, $active_month, $active_day;
private $events = [];
public function __construct($date = null) {
$this->active_year = $date != null ? date('Y', strtotime($date)) : date('Y');
$this->active_month = $date != null ? date('m', strtotime($date)) : date('m');
$this->active_day = $date != null ? date('d', strtotime($date)) : date('d');
}
public function add_event($txt, $date, $days = 1, $color = '') {
$color = $color ? ' ' . $color : $color;
$this->events[] = [$txt, $date, $days, $color];
}
public function __toString() {
$num_days = date('t', strtotime($this->active_day . '-' . $this->active_month . '-' . $this->active_year));
$num_days_last_month = date('j', strtotime('last day of previous month', strtotime($this->active_day . '-' . $this->active_month . '-' . $this->active_year)));
$days = [0 => 'Sun', 1 => 'Mon', 2 => 'Tue', 3 => 'Wed', 4 => 'Thu', 5 => 'Fri', 6 => 'Sat'];
$first_day_of_week = array_search(date('D', strtotime($this->active_year . '-' . $this->active_month . '-1')), $days);
$html = '<div class="calendar">';
$html .= '<div class="header">';
$html .= '<div class="month-year">';
$html .= date('F Y', strtotime($this->active_year . '-' . $this->active_month . '-' . $this->active_day));
$html .= '</div>';
$html .= '</div>';
$html .= '<div class="days">';
foreach ($days as $day) {
$html .= '
<div class="day_name">
' . $day . '
</div>
';
}
for ($i = $first_day_of_week; $i > 0; $i--) {
$html .= '
<div class="day_num ignore">
' . ($num_days_last_month-$i+1) . '
</div>
';
}
for ($i = 1; $i <= $num_days; $i++) {
$selected = '';
if ($i == $this->active_day) {
$selected = ' selected';
}
$html .= '<div class="day_num' . $selected . '">';
$html .= '<span>' . $i . '</span>';
foreach ($this->events as $event) {
for ($d = 0; $d <= ($event[2]-1); $d++) {
if (date('y-m-d', strtotime($this->active_year . '-' . $this->active_month . '-' . $i . ' -' . $d . ' day')) == date('y-m-d', strtotime($event[1]))) {
$html .= '<div class="event' . $event[3] . '">';
$html .= '<a style="color: white;" href="./events.php">' . $event[0] . '</a>';
$html .= '</div>';
}
}
}
$html .= '</div>';
}
for ($i = 1; $i <= (42-$num_days-max($first_day_of_week, 0)); $i++) {
$html .= '
<div class="day_num ignore">
' . $i . '
</div>
';
}
$html .= '</div>';
$html .= '</div>';
return $html;
}
}
?>
</body>
</html>