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