Mercurial > hg > lukkari
annotate index.php @ 78:2f9c78c68a2c
Add link to the XML.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 24 Oct 2012 07:52:03 +0300 |
parents | 241839ebb09f |
children | 7dd647a01fb6 |
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( | |
73 | 32 "en" => "Contact <b>%1</b> tai <b>%2</b>. The author can't be held responsible for any errors in the data!", |
33 "fi" => "Yhteydenotot <b>%1</b> tai <b>%2</b>. En vastaa mahdollisista virheistä tiedoissa!", | |
63 | 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.", |
73 | 38 "fi" => " HUOM! Lukkari v2.0beta on vielä kehityksen alla. Bugeja voi löytyä. 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 | |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
179 function lukGetClassInfo($grouped, $data) |
59 | 180 { |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
181 if ($grouped) |
59 | 182 { |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
183 $out = "<table><tr>"; |
59 | 184 |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
185 $maxCount = 0; |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
186 foreach ($data as $col) |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
187 { |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
188 $out .= "<td>".lukMatchCourse($col[0])."</td>"; |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
189 if (count($col) > $maxCount) |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
190 $maxCount = count($col); |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
191 } |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
192 $out .= "</tr>"; |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
193 |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
194 for ($i = 1; $i < $maxCount; $i++) |
59 | 195 { |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
196 $out .= "<tr>"; |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
197 foreach ($data as $col) |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
198 { |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
199 $out .= "<td>"; |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
200 if (isset($col[$i])) |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
201 $out .= lukChEntities($col[$i]); |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
202 $out .= "</td>"; |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
203 } |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
204 $out .= "</tr>"; |
59 | 205 } |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
206 |
59 | 207 return $out."</table>"; |
208 } | |
209 else | |
210 { | |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
211 $out = lukMatchCourse($data[0][0])."<br />"; |
59 | 212 |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
213 for ($i = 1; $i < count($data[0]); $i++) |
59 | 214 { |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
215 $out .= lukChEntities($data[0][$i])."<br />"; |
59 | 216 } |
217 | |
218 return $out; | |
219 } | |
220 } | |
221 | |
222 | |
223 function lukFindClass($day, $hour) | |
224 { | |
225 global $classHourDefs, $classDayTable; | |
226 if (isset($classDayTable[$day])) | |
227 { | |
228 foreach ($classDayTable[$day] as $id) | |
229 { | |
230 if ($hour >= $classHourDefs[$id]["start"] && | |
231 $hour < $classHourDefs[$id]["start"] + $classHourDefs[$id]["hours"]) | |
232 return $id; | |
233 } | |
234 } | |
235 return 0; | |
236 } | |
237 | |
238 | |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
239 // Check given parameters |
59 | 240 if (isset($_GET["luokka"])) |
241 { | |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
242 $luokka = $_GET["luokka"]; |
66
6315df2faeec
Remove a lingering miniMode variable check.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
243 if (lukCheckClassID($luokka)) |
59 | 244 { |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
245 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
|
246 } |
59 | 247 } |
248 else | |
249 if (isset($_COOKIE["lukluokka"])) | |
250 { | |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
251 $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
|
252 lukCheckClassID($luokka); |
59 | 253 } |
254 else | |
255 { | |
63 | 256 errorMsg(lukMsg("classNotSet", $classDefault)); |
257 $luokka = $classDefault; | |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
258 } |
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
259 |
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
260 |
63 | 261 if (isset($_GET["lang"])) |
262 { | |
263 $tmp = strtolower($_GET["lang"]); | |
264 if (in_array($tmp, $pageLanguages)) | |
265 { | |
266 $pageLang = $tmp; | |
267 setcookie("luklang", $tmp, time() + 365*24*60*60); // expire in a year | |
268 } | |
269 } | |
270 else | |
271 if (isset($_COOKIE["luklang"])) | |
272 { | |
273 $tmp = $_COOKIE["luklang"]; | |
274 if (in_array($tmp, $pageLanguages)) | |
275 $pageLang = $tmp; | |
276 } | |
277 | |
278 | |
279 | |
59 | 280 if (isset($_GET["next"])) |
281 { | |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
282 $nextPeriod = TRUE; |
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
283 $dataFile = "cache-next/".$luokka.".data"; |
59 | 284 } |
285 else | |
286 { | |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
287 $nextPeriod = FALSE; |
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
288 $dataFile = "cache/".$luokka.".data"; |
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
289 } |
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
290 |
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
291 |
1 | 292 // Global cache for course data |
293 $cache = array(); | |
294 $cacheDirty = FALSE; | |
295 | |
296 // Try to read cachefile, if we can get file lock on it | |
297 $fp = @fopen($cacheFile, "rb"); | |
59 | 298 if ($fp) |
299 { | |
300 if (flock($fp, LOCK_SH)) | |
301 { | |
1 | 302 require($cacheFile); |
303 flock($fp, LOCK_UN); | |
304 } | |
305 fclose($fp); | |
306 } | |
307 | |
43
7621bfc47491
Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
308 |
28 | 309 // Read classfile |
59 | 310 $classes = array(); |
5 | 311 $fp = @fopen($classFile, "rb"); |
59 | 312 if ($fp) |
313 { | |
314 if (flock($fp, LOCK_SH)) | |
315 { | |
316 while (!feof($fp)) | |
317 { | |
5 | 318 $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
|
319 if (strlen($str) > 2 && $str[0] != "#") |
5 | 320 $classes[] = $str; |
321 } | |
322 flock($fp, LOCK_UN); | |
323 } | |
324 fclose($fp); | |
59 | 325 } |
326 else | |
327 { | |
44
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
328 errorMsg("Luokkien listaa ei löytynyt. Kokeile ladata sivu uudelleen hetken kuluttua."); |
1 | 329 } |
330 | |
331 | |
59 | 332 if (!file_exists($dataFile)) |
333 { | |
44
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
334 errorMsg("Luokan ".lukChEntities($luokka)." tietoja ei löytynyt! ". |
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
335 "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
|
336 "päivityksen aikana. Luokkatiedot päivitetään kerran viikossa."); |
5 | 337 $haveData = FALSE; |
1 | 338 } |
59 | 339 else |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
340 { |
59 | 341 require($dataFile); |
342 $haveData = isset($classInfo); | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
343 } |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
344 |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
345 |
59 | 346 function lukNormalTimeTable() |
347 { | |
63 | 348 global $classInfo, $classHourDefs, $classHourTimes; |
20 | 349 |
71
0329105ddedc
Fix grouped + active state display.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
350 // $currStamp = time() + ((3 * 60) + 45) * 60; |
59 | 351 $currStamp = time(); |
352 $currTime = $currStamp - mktime(0, 0, 0); | |
63 | 353 $currDay = lukGetWeekdayFromTimestamp($currStamp); |
59 | 354 |
5 | 355 // Create the timetable table |
356 $out = | |
357 "<p>".join("; ", $classInfo["general"])."</p>\n". | |
63 | 358 "<div>".lukMsg("viikossa", $classInfo["totalHours"])."</div>\n". |
5 | 359 "<table class=\"timetable\">". |
360 " <tr>\n <th></th>\n"; | |
59 | 361 $cellWidth = 100 / $classInfo["maxDays"]; |
362 if ($cellWidth > 25) $cellWidth = 25; | |
363 for ($day = 0; $day < $classInfo["maxDays"]; $day++) | |
364 { | |
63 | 365 $out .= " <th style=\"width: ".$cellWidth."%;\" class=\"days\">".lukGetDayName($day)."</th>\n"; |
5 | 366 } |
367 $out .= " </tr>\n"; | |
1 | 368 |
59 | 369 for ($hour = $classInfo["firstHour"]; $hour < $classInfo["lastHour"]; $hour++) |
370 { | |
44
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
371 $out .= " <tr>\n". |
59 | 372 " <th class=\"hours\">".lukGetHourStr($hour)."</th>\n"; |
373 for ($day = 0; $day < $classInfo["maxDays"]; $day++) | |
374 { | |
375 $id = lukFindClass($day, $hour); | |
376 if ($id > 0) | |
377 { | |
378 $class = &$classHourDefs[$id]; | |
379 if (!isset($class["set"])) | |
380 { | |
381 $class["set"] = TRUE; | |
382 | |
383 $isActive = $day == $currDay && | |
384 $currTime >= $classHourTimes[$class["start"]]["start"] && | |
385 $currTime < $classHourTimes[$class["start"] + $class["hours"] - 1]["end"]; | |
386 | |
387 $out .= " <td rowspan=\"".$class["hours"]. | |
71
0329105ddedc
Fix grouped + active state display.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
388 "\" class=\"".($isActive ? "clactive " : "").($class["grouped"] ? "clgrouped" : "clnormal")."\">". |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
389 lukGetClassInfo($class["grouped"], $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
|
390 "<div class=\"nhours\"><span>".$class["hours"]."h</span></div></td>\n"; |
59 | 391 } |
392 } | |
393 else | |
394 { | |
395 $out .= " <td class=\"clnothing\"></td>\n"; | |
396 } | |
44
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
397 } |
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
398 $out .= " </tr>\n"; |
1 | 399 } |
400 | |
59 | 401 return $out."</table>\n"; |
402 } | |
5 | 403 |
404 | |
59 | 405 // |
406 // | |
407 // | |
5 | 408 $pageTitle = $haveData ? $luokka." / ".join("; ", $classInfo["info"]) : $luokka; |
409 printPageHeader($pageTitle); | |
18 | 410 |
59 | 411 echo "<form id=\"controls\" action=\"".$baseURI."\" method=\"get\"> |
30 | 412 <table> |
413 <tr> | |
45
d8a1e85b8dda
Change the visual style a tiny bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
414 <th> |
30 | 415 <select name=\"luokka\"> |
416 "; | |
5 | 417 |
418 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
|
419 echo " <option ".($luokka == $class ? "selected=\"selected\" " : "")."value=\"".$class."\">".lukChEntities($class)."</option>\n"; |
1 | 420 } |
30 | 421 echo |
422 " </select> | |
45
d8a1e85b8dda
Change the visual style a tiny bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
423 </th> |
63 | 424 <th><input class=\"submit\" type=\"submit\" value=\"".lukMsg("Switch")."\" /></th> |
425 <th><a href=\"http://www.oamk.fi/tyojarjestykset/otek/luokat/OR_".$luokka.".htm\">".lukMsg("Original")."</a></th> | |
17 | 426 |
63 | 427 <th><a href=\"".$baseURI.($nextPeriod ? "" : "?next")."\">". |
428 ($nextPeriod ? lukMsg("Current period") : lukMsg("Next period"))."</a></th> | |
78 | 429 |
430 <th><a href=\"".$baseURI.($nextPeriod ? "cache-next" : "cache")."/".$luokka.".xml\">XML</a></th> | |
30 | 431 </tr> |
432 </table> | |
433 </form> | |
434 "; | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
435 |
18 | 436 echo "<h1>".$pageTitle."</h1>\n"; |
1 | 437 |
438 // Show error messages | |
59 | 439 if ($errorSet) |
440 { | |
1 | 441 echo "<ul>\n"; |
44
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
442 foreach ($errorMsgs as $msg) |
1 | 443 echo "<li>$msg</li>\n"; |
444 echo "</ul>\n"; | |
445 } | |
446 | |
59 | 447 if ($haveData) |
448 { | |
449 echo lukNormalTimeTable(); | |
450 } | |
5 | 451 |
73 | 452 echo |
453 "<div id=\"footer\">". | |
454 lukMsg("contact", "ccr @ IRCNet", "ccr (at) tnsp (dot) org"). | |
455 " <div style=\"color: red;\">".lukMsg("beta")."</div> | |
30 | 456 </div> |
48
d41b51cd4ae5
Implement switchable CSS support and a new default style + very minor code
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
457 <div id=\"csssel\"> |
73 | 458 <div id=\"ctitle\">Lukkari v2.0 beta</div> |
459 <div>".lukMsg("Style").": "; | |
63 | 460 |
49
16aea8e5cb71
Improved CSS, added a third stylesheet option.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
461 foreach ($pageCSSAlts as $name => $id) |
69 | 462 echo "<a href=\"".$baseURI."?css=".$id."\">".$name."</a>"; |
63 | 463 |
73 | 464 echo "</div> |
465 <div id=\"clang\">"; | |
63 | 466 foreach ($pageLanguages as $id) |
69 | 467 echo "<a href=\"".$baseURI."?lang=".$id."\">".$id."</a>"; |
63 | 468 |
73 | 469 echo "</div> |
63 | 470 </div> |
30 | 471 "; |
1 | 472 printPageFooter(); |
473 | |
474 | |
475 // 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
|
476 if ($cacheDirty) |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
477 { |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
478 $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
|
479 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
|
480 // Can't do much anything here .. |
1 | 481 } |
482 } | |
483 | |
484 ?> |