Mercurial > hg > lukkari
annotate index.php @ 68:0acf6e16af93
Add another stylesheet, a dark one.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 24 Oct 2012 03:45:28 +0300 |
parents | 6315df2faeec |
children | e370345d0562 |
rev | line source |
---|---|
59 | 1 <?php |
43
7621bfc47491
Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
2 // |
65 | 3 // Lukkari v2.0 |
4 // (C) Copyright 2010 - 2012 Matti 'ccr' Hämäläinen <ccr@tnsp.org> | |
5 // Yes, this code is rather horrible. :| | |
43
7621bfc47491
Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
6 // |
64
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
7 $pageLang = "fi"; |
38
2195ede068c8
Add chentities() helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
8 $pageCharset = "utf-8"; |
2195ede068c8
Add chentities() helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
9 $internalCharset = "utf-8"; |
63 | 10 $classDefault = "TTE9SNO"; |
65 | 11 $classFile = "classes.txt"; |
1 | 12 $cacheFile = "coursecache.txt"; |
63 | 13 $baseURI = "http://tnsp.org/luk/"; |
1 | 14 |
48
d41b51cd4ae5
Implement switchable CSS support and a new default style + very minor code
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
15 $pageCSSData = array("cookie" => "lukcss", "prefix" => $baseURI."luk"); |
68
0acf6e16af93
Add another stylesheet, a dark one.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
16 $pageCSSAlts = array("blue" => "1", "old" => "2", "purple" => "3", "dark" => "4"); |
48
d41b51cd4ae5
Implement switchable CSS support and a new default style + very minor code
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
17 |
63 | 18 $pageLanguages = array("fi", "en"); |
19 | |
20 $lukDayNames = array( | |
21 "fi" => array("Maanantai", "Tiistai", "Keskiviikko", "Torstai", "Perjantai", "Lauantai", "Sunnuntai"), | |
22 "en" => array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"), | |
23 ); | |
24 | |
25 $lukTranslations = array( | |
26 "Original" => array("fi" => "Alkuperäinen"), | |
27 "Next period" => array("fi" => "Seuraava periodi"), | |
28 "Current period" => array("fi" => "Nykyinen periodi"), | |
29 "Switch" => array("fi" => "Vaihda"), | |
30 | |
31 "contact" => array( | |
32 "en" => "Contact <b>ccr @ IRCNet</b> tai <b>ccr at tnsp dot org</b>. The author can't be held responsible for any errors in the data!", | |
33 "fi" => "Yhteydenotot <b>ccr @ IRCNet</b> tai <b>ccr at tnsp dot org</b>. En vastaa mahdollisista virheistä tiedoissa!", | |
34 ), | |
35 | |
36 "beta" => array( | |
64
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
37 "en" => " NOTICE! Lukkari v2.0beta is still under development. There may be bugs. Some old features (mini-mode) may not return.", |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
38 "fi" => " HUOM! Lukkari v2.0beta on vielä keskeneräinen. Bugeja voi olla. Jotkut vanhat ominaisuudet (mini-moodi) eivät välttämättä tule takaisin.", |
63 | 39 ), |
40 | |
41 "viikossa" => array( | |
42 "en" => "Total of <b>%1</b> hours in the week.", | |
43 "fi" => "Viikossa yhteensä <b>%1</b> tuntia.", | |
44 ), | |
45 | |
46 "classNotSet" => array( | |
47 "en" => "Class not set, using default <b>%1</b>.", | |
48 "fi" => "Luokkaa ei asetettu, käytetään vakioarvoa <b>%1</b>.", | |
49 ), | |
50 | |
51 "Style" => array("fi" => "Tyyli"), | |
52 // "" => array("fi" => ), | |
53 ); | |
54 | |
55 | |
5 | 56 // Include framework |
1 | 57 require "mcommon.inc.php"; |
58 require "merrors.inc.php"; | |
59 | |
2 | 60 |
63 | 61 // Translation function |
62 function lukMsg($msg) | |
63 { | |
64 global $lukTranslations, $pageLang; | |
65 | |
66 if (isset($lukTranslations[$msg]) && isset($lukTranslations[$msg][$pageLang])) | |
67 $str = $lukTranslations[$msg][$pageLang]; | |
68 else | |
69 $str = $msg; | |
70 | |
71 foreach (func_get_args() as $argn => $argv) | |
72 { | |
73 $str = preg_replace("/\%".$argn."/", $argv, $str); | |
74 } | |
75 return $str; | |
76 } | |
77 | |
78 | |
79 function lukGetDayName($day) | |
80 { | |
81 global $lukDayNames, $pageLang; | |
82 | |
83 if (isset($lukDayNames[$pageLang]) && isset($lukDayNames[$pageLang][$day])) | |
84 return $lukDayNames[$pageLang][$day]; | |
85 else | |
86 return $lukDayNames["en"][$day]; | |
87 } | |
88 | |
89 | |
43
7621bfc47491
Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
90 function lukChEntities($str) |
38
2195ede068c8
Add chentities() helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
91 { |
2195ede068c8
Add chentities() helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
92 global $internalCharset; |
2195ede068c8
Add chentities() helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
93 return htmlentities($str, ENT_NOQUOTES, $internalCharset); |
2195ede068c8
Add chentities() helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
94 } |
2195ede068c8
Add chentities() helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
95 |
63 | 96 |
43
7621bfc47491
Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
97 function lukCheckClassID(&$id) |
1 | 98 { |
63 | 99 global $classDefault; |
23
b4b86915ae2c
Better input validation for $_GET arguments, thanks to Hjalmarr for pointing out the error.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
100 if (preg_match("#^([A-Z]{3}\d[A-Za-z0-9_]{1,6}|ccr|Ryh_[A-Z]{3}\d[A-Za-z0-9_]{1,6})$#", $id, $m)) { |
b4b86915ae2c
Better input validation for $_GET arguments, thanks to Hjalmarr for pointing out the error.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
101 $id = $m[1]; |
b4b86915ae2c
Better input validation for $_GET arguments, thanks to Hjalmarr for pointing out the error.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
102 return TRUE; |
b4b86915ae2c
Better input validation for $_GET arguments, thanks to Hjalmarr for pointing out the error.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
103 } else { |
63 | 104 errorMsg("Virhe! Luokan täytyy olla muotoa <b>XXXnXXX</b>, käytetään vakioarvoa <b>".$classDefault."</b>."); |
105 $id = $classDefault; | |
1 | 106 return FALSE; |
23
b4b86915ae2c
Better input validation for $_GET arguments, thanks to Hjalmarr for pointing out the error.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
107 } |
1 | 108 } |
109 | |
59 | 110 |
63 | 111 function lukGetWeekdayFromTimestamp($stamp) |
59 | 112 { |
113 $info = getdate($stamp); | |
114 $day = $info["wday"]; | |
115 return ($day > 0) ? $day - 1 : $day + 6; | |
116 } | |
117 | |
118 | |
119 function lukGetHourStamp($stamp) | |
5 | 120 { |
59 | 121 return date("H:i", mktime(0, 0, $stamp, 0, 0, 0)); |
122 } | |
123 | |
124 | |
125 function lukGetHourStr($hour) | |
126 { | |
127 global $classHourTimes; | |
128 if (isset($classHourTimes[$hour])) | |
129 { | |
130 return | |
131 "<br />". | |
132 lukGetHourStamp($classHourTimes[$hour]["start"]). | |
133 " - ". | |
134 lukGetHourStamp($classHourTimes[$hour]["end"]). | |
135 "<br /><br />"; | |
136 } | |
17 | 137 else |
59 | 138 return "ERROR"; |
5 | 139 } |
140 | |
141 | |
43
7621bfc47491
Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
142 function lukMatchCourse($id) |
1 | 143 { |
64
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
144 global $cache, $cacheDirty, $internalCharset, $pageLang; |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
145 |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
146 $uri = "http://www.oamk.fi/opiskelijalle/rakenne/opinto-opas/koulutusohjelmat/?sivu=oj&kieli=".strtoupper($pageLang)."&koodi1=".$id; |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
147 |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
148 // Create the index |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
149 if (!isset($cache[$id])) |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
150 $cache[$id] = array(); |
1 | 151 |
152 // Check if course exists in cache | |
64
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
153 if (!isset($cache[$id][$pageLang])) |
59 | 154 { |
155 // Not cached, try to fetch data | |
1 | 156 $cacheDirty = TRUE; |
64
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
157 $data = @file_get_contents($uri); |
59 | 158 if ($data !== FALSE) |
159 { | |
38
2195ede068c8
Add chentities() helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
160 $data = iconv("iso-8859-1", $internalCharset, $data); |
64
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
161 if (preg_match("#<td class=\"smallheadercell\"><strong>(.+?)\s+(\d+)\s*(op|ECTS\s+cr)\s*</strong></td>#", $data, $m)) |
59 | 162 { |
1 | 163 // Add data to cache |
64
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
164 $cache[$id][$pageLang] = array("desc" => $m[1], "op" => intval($m[2])); |
1 | 165 } |
166 } | |
167 } | |
168 | |
64
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
169 if (isset($cache[$id]) && isset($cache[$id][$pageLang])) |
59 | 170 { |
64
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
171 return "<a target=\"_blank\" title=\"".lukChEntities($id." - ".$cache[$id][$pageLang]["op"]." op"). |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
172 "\" href=\"".lukChEntities($uri)."\">".lukChEntities($cache[$id][$pageLang]["desc"])."</a>"; |
59 | 173 } |
1 | 174 else |
43
7621bfc47491
Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
175 return lukChEntities($id); |
1 | 176 } |
177 | |
178 | |
59 | 179 function lukGetClassInfo($isSplit, $data) |
180 { | |
181 if ($isSplit) | |
182 { | |
183 $out = "<table>". | |
184 "<tr><td>".lukMatchCourse($data[0])."</td><td>".lukMatchCourse($data[1])."</td></tr>"; | |
185 | |
186 for ($i = 2; $i < count($data); $i += 2) | |
187 { | |
188 $out .= "<tr><td>".lukChEntities($data[$i])."</td><td>". | |
189 (isset($data[$i+1]) ? lukChEntities($data[$i+1]) : "")."</td></tr>"; | |
190 } | |
191 | |
192 return $out."</table>"; | |
193 } | |
194 else | |
195 { | |
196 $out = lukMatchCourse($data[0])."<br />"; | |
197 | |
198 for ($i = 1; $i < count($data); $i++) | |
199 { | |
200 $out .= lukChEntities($data[$i])."<br />"; | |
201 } | |
202 | |
203 return $out; | |
204 } | |
205 } | |
206 | |
207 | |
208 function lukGetClassInfoData($id) | |
209 { | |
210 global $classInfo; | |
211 | |
212 if (isset($id)) | |
213 { | |
214 if ($id >= 0 && isset($classInfo[$id])) | |
215 { | |
216 $i = $classInfo[$id]; | |
217 $isSplit = preg_match("/^[A-Z]\d{6}$/", $i["data"][1]); | |
218 return lukGetClassInfo($isSplit, $i["data"]); | |
219 } | |
220 else | |
221 return "<p>Ei tunteja.</p>"; | |
222 } | |
223 else | |
224 return "<p>Ei mitään.</p>"; | |
225 } | |
226 | |
227 | |
228 function lukFindClass($day, $hour) | |
229 { | |
230 global $classHourDefs, $classDayTable; | |
231 if (isset($classDayTable[$day])) | |
232 { | |
233 foreach ($classDayTable[$day] as $id) | |
234 { | |
235 if ($hour >= $classHourDefs[$id]["start"] && | |
236 $hour < $classHourDefs[$id]["start"] + $classHourDefs[$id]["hours"]) | |
237 return $id; | |
238 } | |
239 } | |
240 return 0; | |
241 } | |
242 | |
243 | |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
244 // Check given parameters |
59 | 245 if (isset($_GET["luokka"])) |
246 { | |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
247 $luokka = $_GET["luokka"]; |
66
6315df2faeec
Remove a lingering miniMode variable check.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
248 if (lukCheckClassID($luokka)) |
59 | 249 { |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
250 setcookie("lukluokka", $luokka, time() + 365*24*60*60); // expire in a year |
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
251 } |
59 | 252 } |
253 else | |
254 if (isset($_COOKIE["lukluokka"])) | |
255 { | |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
256 $luokka = $_COOKIE["lukluokka"]; |
43
7621bfc47491
Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
257 lukCheckClassID($luokka); |
59 | 258 } |
259 else | |
260 { | |
63 | 261 errorMsg(lukMsg("classNotSet", $classDefault)); |
262 $luokka = $classDefault; | |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
263 } |
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
264 |
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
265 |
63 | 266 if (isset($_GET["lang"])) |
267 { | |
268 $tmp = strtolower($_GET["lang"]); | |
269 if (in_array($tmp, $pageLanguages)) | |
270 { | |
271 $pageLang = $tmp; | |
272 setcookie("luklang", $tmp, time() + 365*24*60*60); // expire in a year | |
273 } | |
274 } | |
275 else | |
276 if (isset($_COOKIE["luklang"])) | |
277 { | |
278 $tmp = $_COOKIE["luklang"]; | |
279 if (in_array($tmp, $pageLanguages)) | |
280 $pageLang = $tmp; | |
281 } | |
282 | |
283 | |
284 | |
59 | 285 if (isset($_GET["next"])) |
286 { | |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
287 $nextPeriod = TRUE; |
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
288 $dataFile = "cache-next/".$luokka.".data"; |
59 | 289 } |
290 else | |
291 { | |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
292 $nextPeriod = FALSE; |
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
293 $dataFile = "cache/".$luokka.".data"; |
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
294 } |
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
295 |
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
296 |
1 | 297 // Global cache for course data |
298 $cache = array(); | |
299 $cacheDirty = FALSE; | |
300 | |
301 // Try to read cachefile, if we can get file lock on it | |
302 $fp = @fopen($cacheFile, "rb"); | |
59 | 303 if ($fp) |
304 { | |
305 if (flock($fp, LOCK_SH)) | |
306 { | |
1 | 307 require($cacheFile); |
308 flock($fp, LOCK_UN); | |
309 } | |
310 fclose($fp); | |
311 } | |
312 | |
43
7621bfc47491
Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
313 |
28 | 314 // Read classfile |
59 | 315 $classes = array(); |
5 | 316 $fp = @fopen($classFile, "rb"); |
59 | 317 if ($fp) |
318 { | |
319 if (flock($fp, LOCK_SH)) | |
320 { | |
321 while (!feof($fp)) | |
322 { | |
5 | 323 $str = trim(fgets($fp, 128)); |
43
7621bfc47491
Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
324 if (strlen($str) > 2 && $str[0] != "#") |
5 | 325 $classes[] = $str; |
326 } | |
327 flock($fp, LOCK_UN); | |
328 } | |
329 fclose($fp); | |
59 | 330 } |
331 else | |
332 { | |
44
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
333 errorMsg("Luokkien listaa ei löytynyt. Kokeile ladata sivu uudelleen hetken kuluttua."); |
1 | 334 } |
335 | |
336 | |
59 | 337 if (!file_exists($dataFile)) |
338 { | |
44
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
339 errorMsg("Luokan ".lukChEntities($luokka)." tietoja ei löytynyt! ". |
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
340 "Jos luokkakoodi on uusi, ilmestyy se järjestelmään seuraavan ". |
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
341 "päivityksen aikana. Luokkatiedot päivitetään kerran viikossa."); |
5 | 342 $haveData = FALSE; |
1 | 343 } |
59 | 344 else |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
345 { |
59 | 346 require($dataFile); |
347 $haveData = isset($classInfo); | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
348 } |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
349 |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
350 |
59 | 351 function lukNormalTimeTable() |
352 { | |
63 | 353 global $classInfo, $classHourDefs, $classHourTimes; |
20 | 354 |
59 | 355 // $currStamp = time() + 9 * 60 * 60 + 18 * 60; |
356 $currStamp = time(); | |
357 $currTime = $currStamp - mktime(0, 0, 0); | |
63 | 358 $currDay = lukGetWeekdayFromTimestamp($currStamp); |
59 | 359 |
5 | 360 // Create the timetable table |
361 $out = | |
362 "<p>".join("; ", $classInfo["general"])."</p>\n". | |
63 | 363 "<div>".lukMsg("viikossa", $classInfo["totalHours"])."</div>\n". |
5 | 364 "<table class=\"timetable\">". |
365 " <tr>\n <th></th>\n"; | |
59 | 366 $cellWidth = 100 / $classInfo["maxDays"]; |
367 if ($cellWidth > 25) $cellWidth = 25; | |
368 for ($day = 0; $day < $classInfo["maxDays"]; $day++) | |
369 { | |
63 | 370 $out .= " <th style=\"width: ".$cellWidth."%;\" class=\"days\">".lukGetDayName($day)."</th>\n"; |
5 | 371 } |
372 $out .= " </tr>\n"; | |
1 | 373 |
59 | 374 for ($hour = $classInfo["firstHour"]; $hour < $classInfo["lastHour"]; $hour++) |
375 { | |
44
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
376 $out .= " <tr>\n". |
59 | 377 " <th class=\"hours\">".lukGetHourStr($hour)."</th>\n"; |
378 for ($day = 0; $day < $classInfo["maxDays"]; $day++) | |
379 { | |
380 $id = lukFindClass($day, $hour); | |
381 if ($id > 0) | |
382 { | |
383 $class = &$classHourDefs[$id]; | |
384 if (!isset($class["set"])) | |
385 { | |
386 $class["set"] = TRUE; | |
387 | |
388 $isSplit = preg_match("/^[A-Z]\d{6}$/", $class["data"][1]); | |
389 | |
390 $isActive = $day == $currDay && | |
391 $currTime >= $classHourTimes[$class["start"]]["start"] && | |
392 $currTime < $classHourTimes[$class["start"] + $class["hours"] - 1]["end"]; | |
393 | |
394 $out .= " <td rowspan=\"".$class["hours"]. | |
63 | 395 "\" class=\"".($class["grouped"] ? "clgrouped" : ($isActive ? "clactive" : "clnormal"))."\">". |
59 | 396 lukGetClassInfo($isSplit, $class["data"]). |
60
cdc04572800c
Add back the indicator box for number of hours for the class.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
397 "<div class=\"nhours\"><span>".$class["hours"]."h</span></div></td>\n"; |
59 | 398 } |
399 } | |
400 else | |
401 { | |
402 $out .= " <td class=\"clnothing\"></td>\n"; | |
403 } | |
44
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
404 } |
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
405 $out .= " </tr>\n"; |
1 | 406 } |
407 | |
59 | 408 return $out."</table>\n"; |
409 } | |
5 | 410 |
411 | |
59 | 412 // |
413 // | |
414 // | |
5 | 415 $pageTitle = $haveData ? $luokka." / ".join("; ", $classInfo["info"]) : $luokka; |
416 printPageHeader($pageTitle); | |
18 | 417 |
59 | 418 echo "<form id=\"controls\" action=\"".$baseURI."\" method=\"get\"> |
30 | 419 <table> |
420 <tr> | |
45
d8a1e85b8dda
Change the visual style a tiny bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
421 <th> |
30 | 422 <select name=\"luokka\"> |
423 "; | |
5 | 424 |
425 foreach ($classes as $class) { | |
43
7621bfc47491
Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
426 echo " <option ".($luokka == $class ? "selected=\"selected\" " : "")."value=\"".$class."\">".lukChEntities($class)."</option>\n"; |
1 | 427 } |
30 | 428 echo |
429 " </select> | |
45
d8a1e85b8dda
Change the visual style a tiny bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
430 </th> |
63 | 431 <th><input class=\"submit\" type=\"submit\" value=\"".lukMsg("Switch")."\" /></th> |
432 <th><a href=\"http://www.oamk.fi/tyojarjestykset/otek/luokat/OR_".$luokka.".htm\">".lukMsg("Original")."</a></th> | |
17 | 433 |
63 | 434 <th><a href=\"".$baseURI.($nextPeriod ? "" : "?next")."\">". |
435 ($nextPeriod ? lukMsg("Current period") : lukMsg("Next period"))."</a></th> | |
30 | 436 </tr> |
437 </table> | |
438 </form> | |
439 "; | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
440 |
18 | 441 echo "<h1>".$pageTitle."</h1>\n"; |
1 | 442 |
443 // Show error messages | |
59 | 444 if ($errorSet) |
445 { | |
1 | 446 echo "<ul>\n"; |
44
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
447 foreach ($errorMsgs as $msg) |
1 | 448 echo "<li>$msg</li>\n"; |
449 echo "</ul>\n"; | |
450 } | |
451 | |
59 | 452 if ($haveData) |
453 { | |
454 echo lukNormalTimeTable(); | |
455 } | |
5 | 456 |
63 | 457 echo "<div id=\"footer\">". |
458 lukMsg("contact"). | |
64
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
459 "<div style=\"color: red;\">". |
63 | 460 lukMsg("beta"). |
64
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
461 "</div> |
30 | 462 </div> |
48
d41b51cd4ae5
Implement switchable CSS support and a new default style + very minor code
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
463 <div id=\"csssel\"> |
59 | 464 <div id=\"ctitle\">Lukkari v2.0 beta</div> |
63 | 465 <div>".lukMsg("Style").": "; |
466 | |
49
16aea8e5cb71
Improved CSS, added a third stylesheet option.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
467 foreach ($pageCSSAlts as $name => $id) |
48
d41b51cd4ae5
Implement switchable CSS support and a new default style + very minor code
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
468 echo "<a href=\"?css=".$id."\">".$name."</a>"; |
63 | 469 |
470 echo "</div><div id=\"clang\">"; | |
471 foreach ($pageLanguages as $id) | |
472 echo "<a href=\"?lang=".$id."\">".$id."</a>"; | |
473 | |
48
d41b51cd4ae5
Implement switchable CSS support and a new default style + very minor code
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
474 echo " |
d41b51cd4ae5
Implement switchable CSS support and a new default style + very minor code
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
475 </div> |
63 | 476 </div> |
30 | 477 "; |
1 | 478 printPageFooter(); |
479 | |
480 | |
481 // Dump the course data cache, but only if it has changed | |
64
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
482 if ($cacheDirty) |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
483 { |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
484 $str = "<?\n\$cache = ".var_export($cache, TRUE)."\n?>"; |
27
7655db03ea60
Use different strategy of saving course cache, by using file_put_contents() with locking instead of using separate writes.
Matti Hamalainen <ccr@tnsp.org>
parents:
23
diff
changeset
|
485 |
7655db03ea60
Use different strategy of saving course cache, by using file_put_contents() with locking instead of using separate writes.
Matti Hamalainen <ccr@tnsp.org>
parents:
23
diff
changeset
|
486 // Use locking to prevent concurrent access and dump data |
7655db03ea60
Use different strategy of saving course cache, by using file_put_contents() with locking instead of using separate writes.
Matti Hamalainen <ccr@tnsp.org>
parents:
23
diff
changeset
|
487 if (file_put_contents($cacheFile, $str, LOCK_EX) === FALSE) { |
7655db03ea60
Use different strategy of saving course cache, by using file_put_contents() with locking instead of using separate writes.
Matti Hamalainen <ccr@tnsp.org>
parents:
23
diff
changeset
|
488 // Can't do much anything here .. |
1 | 489 } |
490 } | |
491 | |
492 ?> |