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