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