-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcalendar.php
140 lines (125 loc) · 3.14 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!DOCTYPE html>
<html lang="de">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>TimeTrack Jahreskalender</title>
<meta name="author" content="">
<link href="static/css/calendar.css" media="screen" rel="stylesheet" type="text/css">
<link rel="shortcut icon" href="static/img/favicon.ico" />
<link rel="icon" href="static/img/favicon.ico" type="image/ico" />
</head>
<body>
<?php
// Comment
session_start();
include "TimeTrack.class.php";
$timetrack = new TimeTrack();
setlocale(LC_ALL, "de_DE");
$loggedin=false;
$loggedin = $timetrack->login($_POST['u'], $_POST['p'], $_GET['h']);
$hash = $timetrack->hash;
if(!$loggedin) {
unset($hash);
unset($_SESSION['userhash']);
}
if (!$loggedin) {
die('Not logged in');
}
$year = date("Y");
if(isset($_GET['y']) && is_numeric($_GET['y']) && strlen($_GET['y']) == 4) {
$year = $_GET['y'];
}
$holidays = $timetrack->getHolidays($year);
$subjects = $timetrack->getDaySubjectsForYear($year);
for ($month = 1; $month <= 12; $month++)
{
$monthtimestamp = mktime(0, 0, 0, $month, 1, $year);
$monthname = strftime("%B %Y", $monthtimestamp);
$firstweekday = date('w', $monthtimestamp);
if($firstweekday == 0)
$firstweekday = 7; // sunday should be last day
$firstweekday--; // let begin with 0
$week = 1;
?>
<table class="month" cellspacing=0 cellpadding=0>
<thead>
<tr>
<th colspan="7" align="center"><?php echo $monthname; ?></th>
</tr>
</thead>
<tbody>
<tr class="weekdays">
<td>Mo</td>
<td>Di</td>
<td>Mi</td>
<td>Do</td>
<td>Fr</td>
<td class="nobusiness">Sa</td>
<td class="nobusiness">So</td>
</tr>
<tr>
<?php
echo str_repeat('<td> </td>', $firstweekday);
for ($day = 1; $day <= date('t', $monthtimestamp); $day++)
{
$todaytimestamp = mktime(0, 0, 0, $month, $day, $year);
$class = "";
if(isset($subjects[date('Y-m-d', $todaytimestamp)]))
{
$class = " " . $subjects[date('Y-m-d', $todaytimestamp)]['subject'];
}
$weekday = date('w', $todaytimestamp);
if(isset($holidays[$todaytimestamp]))
{
echo "<td class='holiday $class' title='".$holidays[$todaytimestamp]."'>$day</td>";
}
elseif($weekday == 0 || $weekday == 6)
{
echo "<td class='nobusiness $class'>$day</td>";
}
else
{
echo "<td class='$class'>$day</td>";
}
if($weekday == 0) // sunday should be last day
{
echo "</tr><tr>";
$week++;
}
}
// fill last week for empty days
$lastweekday = date('w', mktime(0, 0, 0, $month, $day, $year));
if($lastweekday == 0)
$lastweekday = 7; // sunday should be last day
$lastweekday--; // let begin with 0
echo str_repeat('<td> </td>', 7 - $lastweekday);
// fill every month to six weeks
if($week < 6)
{
for ($missingweek = $week; $missingweek < 6; $missingweek++)
{
echo "</tr><tr>";
echo str_repeat('<td> </td>', 7);
}
}
?>
</tr>
</tbody>
</table>
<?php
}
?>
<br style="clear: both;">
<table cellspacing=0 style="width: 100%; text-align: center;">
<tr>
<th colspan="4">Legende</th>
</tr>
<tr>
<td class="illness">Krank</td>
<td class="vacation">Urlaub</td>
<td class="holiday">Feiertag</td>
<td class="nobusiness">Betriebsfrei</td>
</tr>
</table>
</body>
</html>