-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
213 lines (177 loc) · 5.98 KB
/
index.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php
date_default_timezone_set("America/Los_Angeles");
$start_date = "2013-09-22";
$end_date = "2013-12-13";
$first_day_of_classes = "2013-09-26";
$assignment_file = "assignments.txt";
$quarter_title = "Fall 2013";
$days_of_week = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
$quarter_dates = createDateRangeArray($start_date,$end_date);
$today_date = new DateTime();
$first_day_of_classes = new DateTime($first_day_of_classes);
$assignments = array();
$holidays = array();
?>
<html>
<head>
<title><?php echo $quarter_title; ?> Calendar</title>
<link rel="stylesheet" type="text/css" href="main.css">
<link rel="shortcut icon" href="favicon.ico" />
</head>
<?php
// INPUT ASSIGNMENTS
$handle = fopen($assignment_file, "r");
$assignment_pattern = '/^([a-zA-Z0-9 ]+);([a-zA-Z0-9 #,]+);([a-zA-Z]+);(\d\d\d\d)-(\d\d)-(\d\d)/';
$holiday_pattern = '/^Holiday;([a-zA-Z ]+);(\d\d\d\d)-(\d\d)-(\d\d)/';
while($line = fgets($handle)) {
if(substr(trim($line), 0, 1) == '#') {
continue;
}
if(preg_match($assignment_pattern, $line, $matches)) {
$date_string = "$matches[4]-$matches[5]-$matches[6]";
$this_assignment = new Assignment($matches[1], $matches[3], $matches[2], $date_string);
if(array_key_exists($date_string, $assignments)) {
array_push($assignments[$date_string], $this_assignment);
}
else {
$assignments[$date_string] = array($this_assignment);
}
}
else if(preg_match($holiday_pattern, $line, $matches)) {
print_r($matches);
$date_string = "$matches[2]-$matches[3]-$matches[4]";
if(array_key_exists($date_string, $holidays)) {
array_push($holidays[$date_string], $matches[1]);
}
else {
$holidays[$date_string] = array($matches[1]);
}
}
else {
continue;
}
}
?>
<body background="#000000">
<center>
<h1>
<?php print "$quarter_title\n"; ?>
<br>
</h1>
<table border="4" align="center">
<tr>
<?php
// PRINT COLUMN HEADERS
foreach($days_of_week as $day) {
print "<th class=\"dayHeader\">$day</th>\n";
}
?>
</tr>
<?php
// BUILD CALENDAR
$weeks = -1;
foreach($quarter_dates as $this_date_str) {
$this_date = new DateTime($this_date_str);
$week_day = $this_date->format("w");
$day = $this_date->format("j");
$month = $this_date->format("F");
$year = $this_date->format("Y");
$padded_day = $this_date->format("d");
$padded_month = $this_date->format("m");
$padded_year = $this_date->format("Y");
$date_string = "$padded_year-$padded_month-$padded_day";
if($week_day == 0) {
$weeks++;
echo "<tr>\n";
}
$css_class = "";
if($this_date->format("Y-m-d") < $first_day_of_classes->format("Y-m-d")) {
$css_class = "outside";
}
else if($this_date->format("Y-m-d") < $today_date->format("Y-m-d")) {
$css_class = "past";
}
else if($this_date->format("Y-m-d") == $today_date->format("Y-m-d")) {
$css_class = "today";
}
if(array_key_exists($date_string, $holidays)) {
if($css_class != "") {
$css_class += ",holiday";
}
else {
$css_class = "holiday";
}
}
echo "<td id=\"$date_string\" class =\"$css_class\">";
if($week_day == 0) {
if($weeks == 11) {
$week_title = "Finals Week";
}
else {
$week_title = "Week $weeks";
}
echo "<br><br><h2 class=\"week\">$week_title</h2>\n";
}
else {
if($day == 1) {
echo "<b><span class=\"month\">$month</span> </b>";
}
echo "<b>$day</b><br><br>";
}
// HOLIDAY LOOP
if(array_key_exists($date_string, $holidays)) {
foreach($holidays[$date_string] as $this_holiday) {
print "<span class=\"holiday\"><h3>$this_holiday</h3></span><br>\n";
}
}
// ASSIGNMENT LOOP
if(array_key_exists($date_string, $assignments)) {
foreach($assignments[$date_string] as $this_assignment) {
print "<span class=\"$this_assignment->ass_type\">$this_assignment->ass_class: $this_assignment->ass_name</span><br>\n";
}
}
echo "</td>\n";
if($week_day == 6) {
echo "</tr>\n";
}
}
?>
</table>
</center>
</body>
</html>
<?php
function createDateRangeArray($strDateFrom,$strDateTo)
{
$aryRange=array();
$iDateFrom=mktime(1,0,0,substr($strDateFrom,5,2), substr($strDateFrom,8,2),substr($strDateFrom,0,4));
$iDateTo=mktime(1,0,0,substr($strDateTo,5,2), substr($strDateTo,8,2),substr($strDateTo,0,4));
if ($iDateTo>=$iDateFrom)
{
array_push($aryRange,date('Y-m-d',$iDateFrom)); // first entry
while ($iDateFrom<$iDateTo)
{
$iDateFrom+=86400; // add 24 hours
array_push($aryRange,date('Y-m-d',$iDateFrom));
}
}
return $aryRange;
}
class Assignment
{
public $ass_class;
public $ass_type;
public $ass_name;
public $ass_date;
function __construct($cl, $ty, $na, $da) {
$this->ass_class = $cl;
$this->ass_type = $ty;
$this->ass_name = $na;
$this->ass_date = $da;
}
function getHTMLString()
{
return "<span class=\"$type\">$class: $name</span><br>\n";
}
}
?>