Mercurial > hg > lukkari
annotate index.php @ 84:adaad33f929c
Improve mobile mode.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 24 Oct 2012 14:15:43 +0300 |
parents | 85068c8513b4 |
children | 4a2082f19626 |
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"; |
82
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
11 $classIDFile = "classes.txt"; |
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
12 $courseCacheFile = "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( | |
84 | 37 "en" => " NOTICE! Lukkari v2.0beta is still under development. There may be bugs.", |
38 "fi" => " HUOM! Lukkari v2.0beta on vielä kehityksen alla. Bugeja voi löytyä.", | |
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 |
83 | 240 $mobileMode = FALSE; |
241 if (isset($_GET["m"])) | |
242 { | |
243 $mobileMode = intval($_GET["m"]); | |
244 setcookie("lukmobile", $mobileMode, time() + 365*24*60*60); // expire in a year | |
245 } | |
246 else | |
247 if (isset($_COOKIE["lukmobile"])) | |
248 { | |
249 $mobileMode = $_COOKIE["lukmobile"]; | |
250 } | |
251 | |
252 if ($mobileMode) | |
253 { | |
254 $pageCSSData["prefix"] = $baseURI."mluk"; | |
255 } | |
256 | |
82
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
257 |
59 | 258 if (isset($_GET["luokka"])) |
259 { | |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
260 $luokka = $_GET["luokka"]; |
66
6315df2faeec
Remove a lingering miniMode variable check.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
261 if (lukCheckClassID($luokka)) |
59 | 262 { |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
263 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
|
264 } |
59 | 265 } |
266 else | |
267 if (isset($_COOKIE["lukluokka"])) | |
268 { | |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
269 $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
|
270 lukCheckClassID($luokka); |
59 | 271 } |
272 else | |
273 { | |
63 | 274 errorMsg(lukMsg("classNotSet", $classDefault)); |
275 $luokka = $classDefault; | |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
276 } |
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
277 |
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
278 |
63 | 279 if (isset($_GET["lang"])) |
280 { | |
281 $tmp = strtolower($_GET["lang"]); | |
282 if (in_array($tmp, $pageLanguages)) | |
283 { | |
284 $pageLang = $tmp; | |
285 setcookie("luklang", $tmp, time() + 365*24*60*60); // expire in a year | |
286 } | |
287 } | |
288 else | |
289 if (isset($_COOKIE["luklang"])) | |
290 { | |
291 $tmp = $_COOKIE["luklang"]; | |
292 if (in_array($tmp, $pageLanguages)) | |
293 $pageLang = $tmp; | |
294 } | |
295 | |
296 | |
297 | |
59 | 298 if (isset($_GET["next"])) |
299 { | |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
300 $nextPeriod = TRUE; |
82
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
301 $cachePath = "cache-next/"; |
59 | 302 } |
303 else | |
304 { | |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
305 $nextPeriod = FALSE; |
82
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
306 $cachePath = "cache/"; |
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
307 } |
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
308 |
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
309 if (file_exists($cachePath."baseuri.data")) |
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
310 { |
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
311 require $cachePath."baseuri.data"; |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
312 } |
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
313 |
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
314 |
1 | 315 // Global cache for course data |
316 $cache = array(); | |
317 $cacheDirty = FALSE; | |
318 | |
319 // Try to read cachefile, if we can get file lock on it | |
82
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
320 $fp = @fopen($courseCacheFile, "rb"); |
59 | 321 if ($fp) |
322 { | |
323 if (flock($fp, LOCK_SH)) | |
324 { | |
82
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
325 require($courseCacheFile); |
1 | 326 flock($fp, LOCK_UN); |
327 } | |
328 fclose($fp); | |
329 } | |
330 | |
43
7621bfc47491
Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
331 |
28 | 332 // Read classfile |
59 | 333 $classes = array(); |
82
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
334 $fp = @fopen($classIDFile, "rb"); |
59 | 335 if ($fp) |
336 { | |
337 if (flock($fp, LOCK_SH)) | |
338 { | |
339 while (!feof($fp)) | |
340 { | |
5 | 341 $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
|
342 if (strlen($str) > 2 && $str[0] != "#") |
5 | 343 $classes[] = $str; |
344 } | |
345 flock($fp, LOCK_UN); | |
346 } | |
347 fclose($fp); | |
59 | 348 } |
349 else | |
350 { | |
44
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
351 errorMsg("Luokkien listaa ei löytynyt. Kokeile ladata sivu uudelleen hetken kuluttua."); |
1 | 352 } |
353 | |
354 | |
82
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
355 $dataFile = $cachePath.$luokka.".data"; |
59 | 356 if (!file_exists($dataFile)) |
357 { | |
44
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
358 errorMsg("Luokan ".lukChEntities($luokka)." tietoja ei löytynyt! ". |
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
359 "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
|
360 "päivityksen aikana. Luokkatiedot päivitetään kerran viikossa."); |
5 | 361 $haveData = FALSE; |
1 | 362 } |
59 | 363 else |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
364 { |
59 | 365 require($dataFile); |
366 $haveData = isset($classInfo); | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
367 } |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
368 |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
369 |
83 | 370 function lukPrintTimeTable($mini) |
59 | 371 { |
63 | 372 global $classInfo, $classHourDefs, $classHourTimes; |
20 | 373 |
71
0329105ddedc
Fix grouped + active state display.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
374 // $currStamp = time() + ((3 * 60) + 45) * 60; |
59 | 375 $currStamp = time(); |
376 $currTime = $currStamp - mktime(0, 0, 0); | |
63 | 377 $currDay = lukGetWeekdayFromTimestamp($currStamp); |
79
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
378 |
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
379 $nextStamp = $currStamp + 30 * 60; |
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
380 $nextTime = $nextStamp - mktime(0, 0, 0); |
59 | 381 |
5 | 382 // Create the timetable table |
83 | 383 if ($mini) |
384 { | |
385 $out = | |
386 "<table class=\"timetable\">". | |
387 " <tr>\n <th></th>". | |
388 " <th class=\"days\">".lukGetDayName($currDay)."</th>\n </tr>\n"; | |
389 | |
390 $startDay = $currDay; | |
391 $lastDay = $currDay + 1; | |
392 } | |
393 else | |
59 | 394 { |
83 | 395 $out = |
396 "<p>".join("; ", $classInfo["general"])."</p>\n". | |
397 "<div>".lukMsg("viikossa", $classInfo["totalHours"])."</div>\n". | |
398 "<table class=\"timetable\">". | |
399 " <tr>\n <th></th>\n"; | |
400 $cellWidth = 100 / $classInfo["maxDays"]; | |
401 if ($cellWidth > 25) $cellWidth = 25; | |
402 | |
403 for ($day = 0; $day < $classInfo["maxDays"]; $day++) | |
404 { | |
405 $out .= " <th style=\"width: ".$cellWidth."%;\" class=\"days\">".lukGetDayName($day)."</th>\n"; | |
406 } | |
407 $out .= " </tr>\n"; | |
408 $startDay = 0; | |
409 $lastDay = $classInfo["maxDays"]; | |
5 | 410 } |
83 | 411 |
1 | 412 |
59 | 413 for ($hour = $classInfo["firstHour"]; $hour < $classInfo["lastHour"]; $hour++) |
414 { | |
44
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
415 $out .= " <tr>\n". |
59 | 416 " <th class=\"hours\">".lukGetHourStr($hour)."</th>\n"; |
83 | 417 for ($day = $startDay; $day < $lastDay; $day++) |
59 | 418 { |
419 $id = lukFindClass($day, $hour); | |
420 if ($id > 0) | |
421 { | |
422 $class = &$classHourDefs[$id]; | |
423 if (!isset($class["set"])) | |
424 { | |
425 $class["set"] = TRUE; | |
426 | |
83 | 427 $nextActive = $day == $currDay && |
79
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
428 $nextTime >= $classHourTimes[$class["start"]]["start"] && |
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
429 $nextTime < $classHourTimes[$class["start"] + $class["hours"] - 1]["end"]; |
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
430 |
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
431 $isActive = $day == $currDay && |
59 | 432 $currTime >= $classHourTimes[$class["start"]]["start"] && |
433 $currTime < $classHourTimes[$class["start"] + $class["hours"] - 1]["end"]; | |
434 | |
79
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
435 $out .= " <td rowspan=\"".$class["hours"]."\" class=\"". |
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
436 ($isActive ? "clactive " : ""). |
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
437 (!$isActive && $nextActive ? "clnext " : ""). |
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
438 ($class["grouped"] ? "clgrouped" : "clnormal")."\">". |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
439 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
|
440 "<div class=\"nhours\"><span>".$class["hours"]."h</span></div></td>\n"; |
59 | 441 } |
442 } | |
443 else | |
444 { | |
445 $out .= " <td class=\"clnothing\"></td>\n"; | |
446 } | |
44
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
447 } |
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
448 $out .= " </tr>\n"; |
1 | 449 } |
450 | |
59 | 451 return $out."</table>\n"; |
452 } | |
5 | 453 |
454 | |
59 | 455 // |
456 // | |
457 // | |
5 | 458 $pageTitle = $haveData ? $luokka." / ".join("; ", $classInfo["info"]) : $luokka; |
459 printPageHeader($pageTitle); | |
18 | 460 |
59 | 461 echo "<form id=\"controls\" action=\"".$baseURI."\" method=\"get\"> |
30 | 462 <table> |
463 <tr> | |
45
d8a1e85b8dda
Change the visual style a tiny bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
464 <th> |
30 | 465 <select name=\"luokka\"> |
466 "; | |
5 | 467 |
468 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
|
469 echo " <option ".($luokka == $class ? "selected=\"selected\" " : "")."value=\"".$class."\">".lukChEntities($class)."</option>\n"; |
1 | 470 } |
30 | 471 echo |
472 " </select> | |
45
d8a1e85b8dda
Change the visual style a tiny bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
473 </th> |
63 | 474 <th><input class=\"submit\" type=\"submit\" value=\"".lukMsg("Switch")."\" /></th> |
83 | 475 "; |
17 | 476 |
83 | 477 if (!$mobileMode) |
478 { | |
479 echo " | |
480 <th><a id=\"next\" class=\"textctrl\" href=\"".$baseURI.($nextPeriod ? "" : "?next")."\">". | |
63 | 481 ($nextPeriod ? lukMsg("Current period") : lukMsg("Next period"))."</a></th> |
83 | 482 <th><a id=\"orig\" class=\"textctrl\" href=\"".$origBaseURI.$luokka.$origBaseExt."\">".lukMsg("Original")."</a></th> |
483 <th><a id=\"xml\" class=\"textctrl\" href=\"".$baseURI.$cachePath."/".$luokka.".xml\">XML</a></th> | |
484 "; | |
485 } | |
78 | 486 |
83 | 487 echo " |
488 <th><a id=\"mobile\" class=\"imgctrl\" href=\"".$baseURI."?m=".($mobileMode ? 0 : 1)."\"><img src=\"img/mobile-white.png\" alt=\"Mobile\"></a></th> | |
30 | 489 </tr> |
490 </table> | |
491 </form> | |
492 "; | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
493 |
18 | 494 echo "<h1>".$pageTitle."</h1>\n"; |
1 | 495 |
496 // Show error messages | |
59 | 497 if ($errorSet) |
498 { | |
1 | 499 echo "<ul>\n"; |
44
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
500 foreach ($errorMsgs as $msg) |
1 | 501 echo "<li>$msg</li>\n"; |
502 echo "</ul>\n"; | |
503 } | |
504 | |
59 | 505 if ($haveData) |
506 { | |
83 | 507 echo lukPrintTimeTable($mobileMode); |
59 | 508 } |
5 | 509 |
73 | 510 echo |
511 "<div id=\"footer\">". | |
512 lukMsg("contact", "ccr @ IRCNet", "ccr (at) tnsp (dot) org"). | |
513 " <div style=\"color: red;\">".lukMsg("beta")."</div> | |
30 | 514 </div> |
84 | 515 "; |
516 | |
517 if (!$mobileMode) | |
518 { | |
519 echo "<div id=\"csssel\"> | |
73 | 520 <div id=\"ctitle\">Lukkari v2.0 beta</div> |
521 <div>".lukMsg("Style").": "; | |
63 | 522 |
49
16aea8e5cb71
Improved CSS, added a third stylesheet option.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
523 foreach ($pageCSSAlts as $name => $id) |
69 | 524 echo "<a href=\"".$baseURI."?css=".$id."\">".$name."</a>"; |
63 | 525 |
73 | 526 echo "</div> |
527 <div id=\"clang\">"; | |
63 | 528 foreach ($pageLanguages as $id) |
69 | 529 echo "<a href=\"".$baseURI."?lang=".$id."\">".$id."</a>"; |
63 | 530 |
73 | 531 echo "</div> |
84 | 532 "; |
533 } | |
534 | |
535 echo "</div> | |
30 | 536 "; |
1 | 537 printPageFooter(); |
538 | |
539 | |
540 // 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
|
541 if ($cacheDirty) |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
542 { |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
543 $str = "<?\n\$cache = ".var_export($cache, TRUE)."\n?>"; |
82
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
544 if (file_put_contents($courseCacheFile, $str, LOCK_EX) === FALSE) { |
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
|
545 // Can't do much anything here .. |
1 | 546 } |
547 } | |
548 | |
549 ?> |