Mercurial > hg > lukkari
comparison index.php @ 59:aa201ddd33dd
Cleaned up, v2.0 beta.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 24 Oct 2012 01:31:10 +0300 |
parents | 16aea8e5cb71 |
children | cdc04572800c |
comparison
equal
deleted
inserted
replaced
58:119f0cef6498 | 59:aa201ddd33dd |
---|---|
1 <?php | 1 <?php |
2 // | 2 // |
3 // Yes, this is horrible. :| | 3 // Yes, this is horrible. :| |
4 // | 4 // |
5 $pageCharset = "utf-8"; | 5 $pageCharset = "utf-8"; |
6 $internalCharset = "utf-8"; | 6 $internalCharset = "utf-8"; |
7 $luokkaDefault = "TTE9SNO"; | 7 $luokkaDefault = "TTE9SNO"; |
8 $classFile = "luokat.txt"; | 8 $classFile = "luokat.txt"; |
9 $cacheFile = "coursecache.txt"; | 9 $cacheFile = "coursecache.txt"; |
10 $baseURI = "http://tnsp.org/luk/"; | 10 $baseURI = "http://tnsp.org/luk2/"; |
11 //$infoURI = "http://www.oamk.fi/opiskelijalle/rakenne/opinto-opas/koulutusohjelmat/?sivu=oj&kieli=FI&opas=2010-2011&vuosi=10S11K&koodi1="; | 11 //$infoURI = "http://www.oamk.fi/opiskelijalle/rakenne/opinto-opas/koulutusohjelmat/?sivu=oj&kieli=FI&opas=2010-2011&vuosi=10S11K&koodi1="; |
12 $infoURI = "http://www.oamk.fi/opiskelijalle/rakenne/opinto-opas/koulutusohjelmat/?sivu=oj&kieli=FI&koodi1="; | 12 $infoURI = "http://www.oamk.fi/opiskelijalle/rakenne/opinto-opas/koulutusohjelmat/?sivu=oj&kieli=FI&koodi1="; |
13 $dayNames = array("Maanantai", "Tiistai", "Keskiviikko", "Torstai", "Perjantai", "Lauantai", "Sunnuntai"); | 13 $dayNames = array("Maanantai", "Tiistai", "Keskiviikko", "Torstai", "Perjantai", "Lauantai", "Sunnuntai"); |
14 | 14 |
15 $pageCSSData = array("cookie" => "lukcss", "prefix" => $baseURI."luk"); | 15 $pageCSSData = array("cookie" => "lukcss", "prefix" => $baseURI."luk"); |
16 $pageCSSAlts = array("blue" => "1", "old" => "2", "purple" => "3"); | 16 $pageCSSAlts = array("blue" => "1", "old" => "2", "purple" => "3"); |
17 | |
18 $hourStamps = array( | |
19 array( 8, 15), | |
20 array( 9, 15), | |
21 array(10, 15), | |
22 array(11, 15), | |
23 array(12, 15), | |
24 array(13, 15), | |
25 array(14, 15), | |
26 array(15, 15), | |
27 array(16, 15), | |
28 array(17, 5), | |
29 array(18, 5), | |
30 array(19, 0), | |
31 array(20, 45), | |
32 ); | |
33 | 17 |
34 // Include framework | 18 // Include framework |
35 require "mcommon.inc.php"; | 19 require "mcommon.inc.php"; |
36 require "merrors.inc.php"; | 20 require "merrors.inc.php"; |
37 | 21 |
55 $id = $luokkaDefault; | 39 $id = $luokkaDefault; |
56 return FALSE; | 40 return FALSE; |
57 } | 41 } |
58 } | 42 } |
59 | 43 |
60 function lukMakeHourStamp($hour, $sec = 0, $mon = 0, $day = 0, $year = 0) | 44 |
61 { | 45 function lukGetDayFromTimestamp($stamp) |
62 global $hourStamps; | 46 { |
63 if (isset($hourStamps[$hour])) | 47 $info = getdate($stamp); |
64 return mktime($hourStamps[$hour][0], $hourStamps[$hour][1], $sec, $mon, $year); | 48 $day = $info["wday"]; |
49 return ($day > 0) ? $day - 1 : $day + 6; | |
50 } | |
51 | |
52 | |
53 function lukGetHourStamp($stamp) | |
54 { | |
55 return date("H:i", mktime(0, 0, $stamp, 0, 0, 0)); | |
56 } | |
57 | |
58 | |
59 function lukGetHourStr($hour) | |
60 { | |
61 global $classHourTimes; | |
62 if (isset($classHourTimes[$hour])) | |
63 { | |
64 return | |
65 "<br />". | |
66 lukGetHourStamp($classHourTimes[$hour]["start"]). | |
67 " - ". | |
68 lukGetHourStamp($classHourTimes[$hour]["end"]). | |
69 "<br /><br />"; | |
70 } | |
65 else | 71 else |
66 return mktime($hour + 8, 0, $sec, $mon, $year); | 72 return "ERROR"; |
67 } | |
68 | |
69 | |
70 function getHour($hour) | |
71 { | |
72 $stamp = lukMakeHourStamp($hour); | |
73 return "<br />".date("H:i", $stamp)." - ".date("H:i", $stamp + 45 * 60)."<br /><br />"; | |
74 } | 73 } |
75 | 74 |
76 | 75 |
77 function lukMatchCourse($id) | 76 function lukMatchCourse($id) |
78 { | 77 { |
79 global $cache, $infoURI, $cacheDirty, $internalCharset; | 78 global $cache, $infoURI, $cacheDirty, $internalCharset; |
80 | 79 |
81 // Check if course exists in cache | 80 // Check if course exists in cache |
82 if (!isset($cache[$id])) { | 81 if (!isset($cache[$id])) |
82 { | |
83 // Not cached, try to fetch data | |
83 $cacheDirty = TRUE; | 84 $cacheDirty = TRUE; |
84 // Not cached, try to fetch data | |
85 $data = @file_get_contents($infoURI.$id); | 85 $data = @file_get_contents($infoURI.$id); |
86 if ($data !== FALSE) { | 86 if ($data !== FALSE) |
87 { | |
87 $data = iconv("iso-8859-1", $internalCharset, $data); | 88 $data = iconv("iso-8859-1", $internalCharset, $data); |
88 if (preg_match("#<td class=\"smallheadercell\"><strong>(.+?)\s+(\d+)\s*op\s*</strong></td>#", $data, $m)) { | 89 if (preg_match("#<td class=\"smallheadercell\"><strong>(.+?)\s+(\d+)\s*op\s*</strong></td>#", $data, $m)) |
90 { | |
89 // Add data to cache | 91 // Add data to cache |
90 $cache[$id] = array("desc" => $m[1], "op" => intval($m[2])); | 92 $cache[$id] = array("desc" => $m[1], "op" => intval($m[2])); |
91 } | 93 } |
92 } | 94 } |
93 } | 95 } |
94 | 96 |
95 if (isset($cache[$id])) | 97 if (isset($cache[$id])) |
98 { | |
96 return "<a target=\"_blank\" title=\"".lukChEntities($id." - ".$cache[$id]["op"]." op"). | 99 return "<a target=\"_blank\" title=\"".lukChEntities($id." - ".$cache[$id]["op"]." op"). |
97 "\" href=\"".lukChEntities($infoURI.$id)."\">".lukChEntities($cache[$id]["desc"])."</a>"; | 100 "\" href=\"".lukChEntities($infoURI.$id)."\">".lukChEntities($cache[$id]["desc"])."</a>"; |
101 } | |
98 else | 102 else |
99 return lukChEntities($id); | 103 return lukChEntities($id); |
100 } | 104 } |
101 | 105 |
102 | 106 |
107 function lukGetClassInfo($isSplit, $data) | |
108 { | |
109 if ($isSplit) | |
110 { | |
111 $out = "<table>". | |
112 "<tr><td>".lukMatchCourse($data[0])."</td><td>".lukMatchCourse($data[1])."</td></tr>"; | |
113 | |
114 for ($i = 2; $i < count($data); $i += 2) | |
115 { | |
116 $out .= "<tr><td>".lukChEntities($data[$i])."</td><td>". | |
117 (isset($data[$i+1]) ? lukChEntities($data[$i+1]) : "")."</td></tr>"; | |
118 } | |
119 | |
120 return $out."</table>"; | |
121 } | |
122 else | |
123 { | |
124 $out = lukMatchCourse($data[0])."<br />"; | |
125 | |
126 for ($i = 1; $i < count($data); $i++) | |
127 { | |
128 $out .= lukChEntities($data[$i])."<br />"; | |
129 } | |
130 | |
131 return $out; | |
132 } | |
133 } | |
134 | |
135 | |
136 function lukGetClassInfoData($id) | |
137 { | |
138 global $classInfo; | |
139 | |
140 if (isset($id)) | |
141 { | |
142 if ($id >= 0 && isset($classInfo[$id])) | |
143 { | |
144 $i = $classInfo[$id]; | |
145 $isSplit = preg_match("/^[A-Z]\d{6}$/", $i["data"][1]); | |
146 return lukGetClassInfo($isSplit, $i["data"]); | |
147 } | |
148 else | |
149 return "<p>Ei tunteja.</p>"; | |
150 } | |
151 else | |
152 return "<p>Ei mitään.</p>"; | |
153 } | |
154 | |
155 | |
156 function lukFindClass($day, $hour) | |
157 { | |
158 global $classHourDefs, $classDayTable; | |
159 if (isset($classDayTable[$day])) | |
160 { | |
161 foreach ($classDayTable[$day] as $id) | |
162 { | |
163 if ($hour >= $classHourDefs[$id]["start"] && | |
164 $hour < $classHourDefs[$id]["start"] + $classHourDefs[$id]["hours"]) | |
165 return $id; | |
166 } | |
167 } | |
168 return 0; | |
169 } | |
170 | |
171 | |
103 // Check for mini-info mode | 172 // Check for mini-info mode |
104 $miniMode = isset($_GET["nyt"]); | 173 $miniMode = isset($_GET["nyt"]); |
105 | 174 |
106 // Check given parameters | 175 // Check given parameters |
107 if (isset($_GET["luokka"])) { | 176 if (isset($_GET["luokka"])) |
177 { | |
108 $luokka = $_GET["luokka"]; | 178 $luokka = $_GET["luokka"]; |
109 if (lukCheckClassID($luokka) && !$miniMode) { | 179 if (lukCheckClassID($luokka) && !$miniMode) |
180 { | |
110 setcookie("lukluokka", $luokka, time() + 365*24*60*60); // expire in a year | 181 setcookie("lukluokka", $luokka, time() + 365*24*60*60); // expire in a year |
111 } | 182 } |
112 } else | 183 } |
113 if (isset($_COOKIE["lukluokka"])) { | 184 else |
185 if (isset($_COOKIE["lukluokka"])) | |
186 { | |
114 $luokka = $_COOKIE["lukluokka"]; | 187 $luokka = $_COOKIE["lukluokka"]; |
115 lukCheckClassID($luokka); | 188 lukCheckClassID($luokka); |
116 } else { | 189 } |
190 else | |
191 { | |
117 errorMsg("Luokkaa ei asetettu, käytetään vakioarvoa <b>".$luokkaDefault."</b>."); | 192 errorMsg("Luokkaa ei asetettu, käytetään vakioarvoa <b>".$luokkaDefault."</b>."); |
118 $luokka = $luokkaDefault; | 193 $luokka = $luokkaDefault; |
119 } | 194 } |
120 | 195 |
121 | 196 |
122 if (isset($_GET["next"])) { | 197 if (isset($_GET["next"])) |
198 { | |
123 $nextPeriod = TRUE; | 199 $nextPeriod = TRUE; |
124 $dataFile = "cache-next/".$luokka.".data"; | 200 $dataFile = "cache-next/".$luokka.".data"; |
125 } else { | 201 } |
202 else | |
203 { | |
126 $nextPeriod = FALSE; | 204 $nextPeriod = FALSE; |
127 $dataFile = "cache/".$luokka.".data"; | 205 $dataFile = "cache/".$luokka.".data"; |
128 } | 206 } |
129 | 207 |
130 | 208 |
132 $cache = array(); | 210 $cache = array(); |
133 $cacheDirty = FALSE; | 211 $cacheDirty = FALSE; |
134 | 212 |
135 // Try to read cachefile, if we can get file lock on it | 213 // Try to read cachefile, if we can get file lock on it |
136 $fp = @fopen($cacheFile, "rb"); | 214 $fp = @fopen($cacheFile, "rb"); |
137 if ($fp) { | 215 if ($fp) |
138 if (flock($fp, LOCK_SH)) { | 216 { |
217 if (flock($fp, LOCK_SH)) | |
218 { | |
139 require($cacheFile); | 219 require($cacheFile); |
140 flock($fp, LOCK_UN); | 220 flock($fp, LOCK_UN); |
141 } | 221 } |
142 fclose($fp); | 222 fclose($fp); |
143 } | 223 } |
144 | 224 |
145 | 225 |
146 // Read classfile | 226 // Read classfile |
227 $classes = array(); | |
147 $fp = @fopen($classFile, "rb"); | 228 $fp = @fopen($classFile, "rb"); |
148 $classes = array(); | 229 if ($fp) |
149 if ($fp) { | 230 { |
150 if (flock($fp, LOCK_SH)) { | 231 if (flock($fp, LOCK_SH)) |
151 while (!feof($fp)) { | 232 { |
233 while (!feof($fp)) | |
234 { | |
152 $str = trim(fgets($fp, 128)); | 235 $str = trim(fgets($fp, 128)); |
153 if (strlen($str) > 2 && $str[0] != "#") | 236 if (strlen($str) > 2 && $str[0] != "#") |
154 $classes[] = $str; | 237 $classes[] = $str; |
155 } | 238 } |
156 flock($fp, LOCK_UN); | 239 flock($fp, LOCK_UN); |
157 } | 240 } |
158 fclose($fp); | 241 fclose($fp); |
159 } else { | 242 } |
243 else | |
244 { | |
160 errorMsg("Luokkien listaa ei löytynyt. Kokeile ladata sivu uudelleen hetken kuluttua."); | 245 errorMsg("Luokkien listaa ei löytynyt. Kokeile ladata sivu uudelleen hetken kuluttua."); |
161 } | 246 } |
162 | 247 |
163 | 248 |
164 if (!file_exists($dataFile)) { | 249 if (!file_exists($dataFile)) |
250 { | |
165 errorMsg("Luokan ".lukChEntities($luokka)." tietoja ei löytynyt! ". | 251 errorMsg("Luokan ".lukChEntities($luokka)." tietoja ei löytynyt! ". |
166 "Jos luokkakoodi on uusi, ilmestyy se järjestelmään seuraavan ". | 252 "Jos luokkakoodi on uusi, ilmestyy se järjestelmään seuraavan ". |
167 "päivityksen aikana. Luokkatiedot päivitetään kerran viikossa."); | 253 "päivityksen aikana. Luokkatiedot päivitetään kerran viikossa."); |
168 $haveData = FALSE; | 254 $haveData = FALSE; |
169 } else { | 255 } |
256 else | |
257 { | |
170 require($dataFile); | 258 require($dataFile); |
171 $haveData = isset($classDefs); | 259 $haveData = isset($classInfo); |
172 } | 260 } |
173 | 261 |
174 | 262 |
175 function lukResolveHours($start, $day, $cmp, $mark = FALSE) | 263 function lukNormalTimeTable() |
176 { | 264 { |
177 global $classHourTable, $classInfo; | 265 global $classInfo, $classHourDefs, $dayNames, $classHourTimes; |
178 $n = 0; | |
179 for ($i = $start; $i < $classInfo["maxhours"]; $i++) | |
180 if ($classHourTable[$i][$day] == $cmp) { | |
181 if ($mark) $classHourTable[$i][$day] = -9999; | |
182 $n++; | |
183 } else | |
184 break; | |
185 return $n; | |
186 } | |
187 | |
188 | |
189 function lukFindNextActiveHour(&$j, &$i, $day, $hour, $chk) | |
190 { | |
191 global $classInfo, $classHourTable; | |
192 // for ($j = $day; $j < $classInfo["maxdays"]; $j++) | |
193 $j = $day; | |
194 for ($i = $hour; $i < $classInfo["maxhours"]; $i++) { | |
195 if ($chk > 0 && $classHourTable[$i][$j] != $chk) | |
196 return $classHourTable[$i][$j]; | |
197 | |
198 if ($classHourTable[$i][$j] > 0 && $classHourTable[$i][$j] != $chk) | |
199 return $classHourTable[$i][$j]; | |
200 } | |
201 | |
202 return -1; | |
203 } | |
204 | |
205 | |
206 function lukGetHourInfo($isSplit, $d) | |
207 { | |
208 if ($isSplit) { | |
209 $out = "<table>". | |
210 "<tr><td>".lukMatchCourse($d[0])."</td><td>".lukMatchCourse($d[1])."</td></tr>"; | |
211 | |
212 for ($i = 2; $i < count($d); $i += 2) | |
213 $out .= "<tr><td>".lukChEntities($d[$i])."</td><td>".(isset($d[$i+1]) ? lukChEntities($d[$i+1]) : "")."</td></tr>"; | |
214 | |
215 return $out."</table>"; | |
216 } else { | |
217 $out = lukMatchCourse($d[0])."<br />"; | |
218 | |
219 for ($i = 1; $i < count($d); $i++) | |
220 $out .= lukChEntities($d[$i])."<br />"; | |
221 | |
222 return $out; | |
223 } | |
224 } | |
225 | |
226 | |
227 function lukGetHourInfoData($id) | |
228 { | |
229 global $classDefs; | |
230 | |
231 if (isset($id)) { | |
232 if ($id >= 0 && isset($classDefs[$id])) { | |
233 $i = $classDefs[$id]; | |
234 $isSplit = preg_match("/^[A-Z]\d{6}$/", $i["data"][1]); | |
235 return lukGetHourInfo($isSplit, $i["data"]); | |
236 } else | |
237 return "<p>Ei tunteja.</p>"; | |
238 } else | |
239 return "<p>Ei mitään.</p>"; | |
240 | |
241 return ""; | |
242 } | |
243 | |
244 | |
245 $out = ""; | |
246 | |
247 if ($miniMode && $haveData) { | |
248 $stamp = time(); | |
249 $aika = getdate($stamp); | |
250 $day = $aika["wday"] - 1; | |
251 if ($day < 0) $day = 7; | |
252 $hour = $aika["hours"] - 8; | |
253 | |
254 $out = "<div class=\"content\">\n"; | |
255 | |
256 if ($hour >= 0 && $day >= 0 && $hour < sizeof($classHourTable)) | |
257 { | |
258 $id = $classHourTable[$hour][$day]; | |
259 $out .= | |
260 "<h2>".$dayNames[$day]." ".date("d.n.Y", $stamp)." - klo ".date("H:i", $stamp)."</h2>\n". | |
261 lukGetHourInfoData($id)."\n"; | |
262 } | |
263 | 266 |
264 | 267 // $currStamp = time() + 9 * 60 * 60 + 18 * 60; |
265 if (isset($id) && $id >= 0 && isset($classDefs[$id])) { | 268 $currStamp = time(); |
266 $i = $classDefs[$id]; | 269 $currTime = $currStamp - mktime(0, 0, 0); |
267 $start = lukMakeHourStamp($i["start"]); | 270 $currDay = lukGetDayFromTimestamp($currStamp); |
268 } | |
269 | |
270 // echo "day=$day, hour=$hour, id=$id<br />\n"; | |
271 | 271 |
272 if ($day >= $classInfo["maxdays"]) { | |
273 $day = $hour = 0; | |
274 $id = -1; | |
275 } else | |
276 if ($hour < 0) { | |
277 $hour = 0; | |
278 $id = -1; | |
279 } else | |
280 if ($hour >= $classInfo["maxhours"]) { | |
281 $day++; | |
282 $hour = 0; | |
283 $id = -1; | |
284 } | |
285 | |
286 // echo "day=$day, hour=$hour, id=$id<br />\n"; | |
287 $found = lukFindNextActiveHour($nday, $nhour, $day, $hour, $id); | |
288 | |
289 // echo "nday=$nday, nhour=$nhour, id=$found<br />\n"; | |
290 | |
291 $out .= "<h2>Seuraavaksi"; | |
292 if ($found > 0) { | |
293 $stamp = lukMakeHourStamp($nhour, 0, 0, $aika["mon"], $aika["mday"] + $nday - $day, $aika["year"]); | |
294 $aika = getdate($stamp); | |
295 $out .= ": ".$dayNames[$nday]." ".date("d.n.Y", $stamp)." - klo ".date("H:i", $stamp)."</h2>\n". | |
296 lukGetHourInfoData($found)."\n"; | |
297 } else { | |
298 $out .= "</h2>\n". | |
299 "<p>Ei mitään</p>\n"; | |
300 } | |
301 | |
302 $out .= "</div>\n"; | |
303 } | |
304 else | |
305 if ($haveData) { | |
306 $totalHours = 0; | |
307 $totalGrouped = 0; | |
308 $dayHours = array(); | |
309 | |
310 for ($day = 0; $day < $classInfo["maxdays"]; $day++) { | |
311 $dayHours[$day]["total"] = $dayHours[$day]["grouped"] = 0; | |
312 | |
313 for ($hour = 0; $hour < $classInfo["maxhours"]; $hour++) { | |
314 $id = $classHourTable[$hour][$day]; | |
315 | |
316 if ($id > 0) { | |
317 $totalHours++; | |
318 $dayHours[$day]["total"]++; | |
319 | |
320 if ($classDefs[$id]["grouped"]) { | |
321 $totalGrouped++; | |
322 $dayHours[$day]["grouped"]++; | |
323 } | |
324 } | |
325 } | |
326 } | |
327 | |
328 // Create the timetable table | 272 // Create the timetable table |
329 $out = | 273 $out = |
330 "<p>".join("; ", $classInfo["general"])."</p>\n". | 274 "<p>".join("; ", $classInfo["general"])."</p>\n". |
331 "<div>Viikossa yhteensä <b>".$totalHours."</b> tuntia, joista <b>".$totalGrouped."</b> ryhmissä tai vuoroviikoin.</div>\n". | 275 "<div>Viikossa yhteensä <b>".$classInfo["totalHours"]."</b> tuntia.</div>\n". |
332 "<table class=\"timetable\">". | 276 "<table class=\"timetable\">". |
333 " <tr>\n <th></th>\n"; | 277 " <tr>\n <th></th>\n"; |
334 for ($day = 0; $day < $classInfo["maxdays"]; $day++) { | 278 $cellWidth = 100 / $classInfo["maxDays"]; |
335 $out .= " <th style=\"width: ".(100 / $classInfo["maxdays"]). | 279 if ($cellWidth > 25) $cellWidth = 25; |
336 "%;\" class=\"days\">".$dayNames[$day]."</th>\n"; | 280 for ($day = 0; $day < $classInfo["maxDays"]; $day++) |
281 { | |
282 $out .= " <th style=\"width: ".$cellWidth."%;\" class=\"days\">".$dayNames[$day]."</th>\n"; | |
337 } | 283 } |
338 $out .= " </tr>\n"; | 284 $out .= " </tr>\n"; |
339 | 285 |
340 for ($hour = 0; $hour < $classInfo["maxhours"]; $hour++) { | 286 for ($hour = $classInfo["firstHour"]; $hour < $classInfo["lastHour"]; $hour++) |
287 { | |
341 $out .= " <tr>\n". | 288 $out .= " <tr>\n". |
342 " <th class=\"hours\">".getHour($hour)."</th>\n"; | 289 " <th class=\"hours\">".lukGetHourStr($hour)."</th>\n"; |
343 for ($day = 0; $day < $classInfo["maxdays"]; $day++) { | 290 for ($day = 0; $day < $classInfo["maxDays"]; $day++) |
344 if (isset($classHourTable[$hour][$day])) { | 291 { |
345 $h = $classHourTable[$hour][$day]; | 292 $id = lukFindClass($day, $hour); |
293 if ($id > 0) | |
294 { | |
295 $class = &$classHourDefs[$id]; | |
296 if (!isset($class["set"])) | |
297 { | |
298 $class["set"] = TRUE; | |
299 | |
300 $isSplit = preg_match("/^[A-Z]\d{6}$/", $class["data"][1]); | |
301 | |
302 $isActive = $day == $currDay && | |
303 $currTime >= $classHourTimes[$class["start"]]["start"] && | |
304 $currTime < $classHourTimes[$class["start"] + $class["hours"] - 1]["end"]; | |
305 | |
306 $out .= " <td rowspan=\"".$class["hours"]. | |
307 "\" class=\"".($class["grouped"] ? "clgrouped" : ($isActive ? "clactive" : "clnormal"))."\">"; | |
308 | |
309 // if ($isActive) | |
310 // $out .= sprintf("%d : %d <> %d, %d -- ", $day, $currTime, $classHourTimes[$class["start"]]["start"], $classHourTimes[$class["start"] + $class["hours"] - 1]["end"]); | |
346 | 311 |
347 if ($h < 1) { | 312 $out .= |
348 if ($h > -9999) { | 313 lukGetClassInfo($isSplit, $class["data"]). |
349 $n = lukResolveHours($hour, $day, $h, TRUE); | 314 "</td>\n"; |
350 $out .= " <td rowspan=\"".$n."\" class=\"clnothing\"></td>\n"; | 315 } |
351 } | 316 } |
352 } else | 317 else |
353 if (isset($classDefs[$h])) { | 318 { |
354 if (!isset($classDefs[$h]["done"])) { | 319 $out .= " <td class=\"clnothing\"></td>\n"; |
355 $classDefs[$h]["done"] = true; | 320 } |
356 $i = $classDefs[$h]; | |
357 $d = $classDefs[$h]["data"]; | |
358 | |
359 $isSplit = preg_match("/^[A-Z]\d{6}$/", $d[1]); | |
360 | |
361 $hours = lukResolveHours($hour, $day, $h, FALSE); | |
362 if ($hours != $i["hours"]) { | |
363 errorMsg("Internal error, cell $hour / $day : hour id $h hours ($hours) do not match ".$i["hours"]."!"); | |
364 } | |
365 | |
366 $out .= " <td rowspan=\"".$hours. | |
367 "\" class=\"".($isSplit || $i["grouped"] ? "clgrouped" : "clnormal")."\">". | |
368 lukGetHourInfo($isSplit, $d). | |
369 "<div class=\"nhours\"><span>".$hours."h</span></div></td>\n"; | |
370 } | |
371 } else | |
372 errorMsg("Internal error cell $hour / $day : hour id $h does not exist!"); | |
373 } else | |
374 errorMsg("Internal error, cell $hour / $day does not exist."); | |
375 } | 321 } |
376 $out .= " </tr>\n"; | 322 $out .= " </tr>\n"; |
377 } | 323 } |
378 | 324 |
379 $out .= "</table>\n"; | 325 return $out."</table>\n"; |
380 | 326 } |
381 } // haveData | 327 |
382 | 328 |
383 | 329 // |
330 // | |
331 // | |
384 $pageTitle = $haveData ? $luokka." / ".join("; ", $classInfo["info"]) : $luokka; | 332 $pageTitle = $haveData ? $luokka." / ".join("; ", $classInfo["info"]) : $luokka; |
385 printPageHeader($pageTitle); | 333 printPageHeader($pageTitle); |
386 | 334 |
387 echo | 335 echo "<form id=\"controls\" action=\"".$baseURI."\" method=\"get\"> |
388 "<form id=\"controls\" action=\"".$baseURI."\" method=\"get\"> | |
389 <table> | 336 <table> |
390 <tr> | 337 <tr> |
391 <th> | 338 <th> |
392 <select name=\"luokka\"> | 339 <select name=\"luokka\"> |
393 "; | 340 "; |
416 "; | 363 "; |
417 | 364 |
418 echo "<h1>".$pageTitle."</h1>\n"; | 365 echo "<h1>".$pageTitle."</h1>\n"; |
419 | 366 |
420 // Show error messages | 367 // Show error messages |
421 if ($errorSet) { | 368 if ($errorSet) |
369 { | |
422 echo "<ul>\n"; | 370 echo "<ul>\n"; |
423 foreach ($errorMsgs as $msg) | 371 foreach ($errorMsgs as $msg) |
424 echo "<li>$msg</li>\n"; | 372 echo "<li>$msg</li>\n"; |
425 echo "</ul>\n"; | 373 echo "</ul>\n"; |
426 } | 374 } |
427 | 375 |
428 echo $out; | 376 if ($haveData) |
377 { | |
378 echo lukNormalTimeTable(); | |
379 } | |
429 | 380 |
430 echo "<div id=\"footer\"> | 381 echo "<div id=\"footer\"> |
431 Yhteydenotot <b>ccr @ IRCNet</b> tai <b>ccr at tnsp dot org</b>. En vastaa mahdollisista virheistä tiedoissa! | 382 Yhteydenotot <b>ccr @ IRCNet</b> tai <b>ccr at tnsp dot org</b>. En vastaa mahdollisista virheistä tiedoissa! |
432 </div> | 383 </div> |
433 <div id=\"csssel\"> | 384 <div id=\"csssel\"> |
385 <div id=\"ctitle\">Lukkari v2.0 beta</div> | |
434 Style: "; | 386 Style: "; |
435 foreach ($pageCSSAlts as $name => $id) | 387 foreach ($pageCSSAlts as $name => $id) |
436 echo "<a href=\"?css=".$id."\">".$name."</a>"; | 388 echo "<a href=\"?css=".$id."\">".$name."</a>"; |
437 echo " | 389 echo " |
438 </div> | 390 </div> |