Mercurial > hg > lukkari
annotate index.php @ 96:0ba79f50e604
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 16 Dec 2012 15:38:46 +0200 |
parents | 171592f906a1 |
children | 6a7172b3a841 |
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( | |
90
556af969a248
Alter the beta status notice a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
37 "en" => " NOTICE! Lukkari v2.0 is still under development. There may be bugs.", |
556af969a248
Alter the beta status notice a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
38 "fi" => " HUOM! Lukkari v2.0 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 ), | |
89
f9cd4c5ca3d6
Translate one more error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
50 |
f9cd4c5ca3d6
Translate one more error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
51 "classDataNotFound" => array( |
f9cd4c5ca3d6
Translate one more error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
52 "fi" => "Luokan %1 tietoja ei löytynyt! Jos luokkakoodi on uusi, ". |
f9cd4c5ca3d6
Translate one more error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
53 "ilmestyy se järjestelmään seuraavan päivityksen aikana. Luokkatiedot ". |
f9cd4c5ca3d6
Translate one more error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
54 "päivitetään kerran viikossa.", |
f9cd4c5ca3d6
Translate one more error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
55 "en" => "Data for class %1 was not found. If the class code is new, it ". |
f9cd4c5ca3d6
Translate one more error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
56 "should appear in this system during the next update. The data is updated ". |
f9cd4c5ca3d6
Translate one more error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
57 "once per week.", |
f9cd4c5ca3d6
Translate one more error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
58 ), |
63 | 59 |
60 "Style" => array("fi" => "Tyyli"), | |
61 // "" => array("fi" => ), | |
62 ); | |
63 | |
64 | |
5 | 65 // Include framework |
1 | 66 require "mcommon.inc.php"; |
67 require "merrors.inc.php"; | |
68 | |
2 | 69 |
63 | 70 // Translation function |
71 function lukMsg($msg) | |
72 { | |
73 global $lukTranslations, $pageLang; | |
74 | |
75 if (isset($lukTranslations[$msg]) && isset($lukTranslations[$msg][$pageLang])) | |
76 $str = $lukTranslations[$msg][$pageLang]; | |
77 else | |
78 $str = $msg; | |
79 | |
80 foreach (func_get_args() as $argn => $argv) | |
81 { | |
82 $str = preg_replace("/\%".$argn."/", $argv, $str); | |
83 } | |
84 return $str; | |
85 } | |
86 | |
87 | |
88 function lukGetDayName($day) | |
89 { | |
90 global $lukDayNames, $pageLang; | |
91 | |
92 if (isset($lukDayNames[$pageLang]) && isset($lukDayNames[$pageLang][$day])) | |
93 return $lukDayNames[$pageLang][$day]; | |
94 else | |
95 return $lukDayNames["en"][$day]; | |
96 } | |
97 | |
98 | |
43
7621bfc47491
Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
99 function lukChEntities($str) |
38
2195ede068c8
Add chentities() helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
100 { |
2195ede068c8
Add chentities() helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
101 global $internalCharset; |
2195ede068c8
Add chentities() helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
102 return htmlentities($str, ENT_NOQUOTES, $internalCharset); |
2195ede068c8
Add chentities() helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
103 } |
2195ede068c8
Add chentities() helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
104 |
63 | 105 |
43
7621bfc47491
Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
106 function lukCheckClassID(&$id) |
1 | 107 { |
63 | 108 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
|
109 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
|
110 $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
|
111 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
|
112 } else { |
63 | 113 errorMsg("Virhe! Luokan täytyy olla muotoa <b>XXXnXXX</b>, käytetään vakioarvoa <b>".$classDefault."</b>."); |
114 $id = $classDefault; | |
1 | 115 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
|
116 } |
1 | 117 } |
118 | |
59 | 119 |
63 | 120 function lukGetWeekdayFromTimestamp($stamp) |
59 | 121 { |
122 $info = getdate($stamp); | |
123 $day = $info["wday"]; | |
124 return ($day > 0) ? $day - 1 : $day + 6; | |
125 } | |
126 | |
127 | |
128 function lukGetHourStamp($stamp) | |
5 | 129 { |
59 | 130 return date("H:i", mktime(0, 0, $stamp, 0, 0, 0)); |
131 } | |
132 | |
133 | |
134 function lukGetHourStr($hour) | |
135 { | |
136 global $classHourTimes; | |
137 if (isset($classHourTimes[$hour])) | |
138 { | |
139 return | |
140 "<br />". | |
141 lukGetHourStamp($classHourTimes[$hour]["start"]). | |
142 " - ". | |
143 lukGetHourStamp($classHourTimes[$hour]["end"]). | |
144 "<br /><br />"; | |
145 } | |
17 | 146 else |
59 | 147 return "ERROR"; |
5 | 148 } |
149 | |
150 | |
43
7621bfc47491
Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
151 function lukMatchCourse($id) |
1 | 152 { |
64
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
153 global $cache, $cacheDirty, $internalCharset, $pageLang; |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
154 |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
155 $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
|
156 |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
157 // Create the index |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
158 if (!isset($cache[$id])) |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
159 $cache[$id] = array(); |
1 | 160 |
161 // Check if course exists in cache | |
64
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
162 if (!isset($cache[$id][$pageLang])) |
59 | 163 { |
164 // Not cached, try to fetch data | |
1 | 165 $cacheDirty = TRUE; |
64
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
166 $data = @file_get_contents($uri); |
59 | 167 if ($data !== FALSE) |
168 { | |
38
2195ede068c8
Add chentities() helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
169 $data = iconv("iso-8859-1", $internalCharset, $data); |
64
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
170 if (preg_match("#<td class=\"smallheadercell\"><strong>(.+?)\s+(\d+)\s*(op|ECTS\s+cr)\s*</strong></td>#", $data, $m)) |
59 | 171 { |
1 | 172 // Add data to cache |
64
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
173 $cache[$id][$pageLang] = array("desc" => $m[1], "op" => intval($m[2])); |
1 | 174 } |
175 } | |
176 } | |
177 | |
64
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
178 if (isset($cache[$id]) && isset($cache[$id][$pageLang])) |
59 | 179 { |
64
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
180 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
|
181 "\" href=\"".lukChEntities($uri)."\">".lukChEntities($cache[$id][$pageLang]["desc"])."</a>"; |
59 | 182 } |
1 | 183 else |
43
7621bfc47491
Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
184 return lukChEntities($id); |
1 | 185 } |
186 | |
187 | |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
188 function lukGetClassInfo($grouped, $data) |
59 | 189 { |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
190 if ($grouped) |
59 | 191 { |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
192 $out = "<table><tr>"; |
59 | 193 |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
194 $maxCount = 0; |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
195 foreach ($data as $col) |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
196 { |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
197 $out .= "<td>".lukMatchCourse($col[0])."</td>"; |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
198 if (count($col) > $maxCount) |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
199 $maxCount = count($col); |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
200 } |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
201 $out .= "</tr>"; |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
202 |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
203 for ($i = 1; $i < $maxCount; $i++) |
59 | 204 { |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
205 $out .= "<tr>"; |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
206 foreach ($data as $col) |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
207 { |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
208 $out .= "<td>"; |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
209 if (isset($col[$i])) |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
210 $out .= lukChEntities($col[$i]); |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
211 $out .= "</td>"; |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
212 } |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
213 $out .= "</tr>"; |
59 | 214 } |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
215 |
59 | 216 return $out."</table>"; |
217 } | |
218 else | |
219 { | |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
220 $out = lukMatchCourse($data[0][0])."<br />"; |
59 | 221 |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
222 for ($i = 1; $i < count($data[0]); $i++) |
59 | 223 { |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
224 $out .= lukChEntities($data[0][$i])."<br />"; |
59 | 225 } |
226 | |
227 return $out; | |
228 } | |
229 } | |
230 | |
231 | |
232 function lukFindClass($day, $hour) | |
233 { | |
234 global $classHourDefs, $classDayTable; | |
235 if (isset($classDayTable[$day])) | |
236 { | |
237 foreach ($classDayTable[$day] as $id) | |
238 { | |
239 if ($hour >= $classHourDefs[$id]["start"] && | |
240 $hour < $classHourDefs[$id]["start"] + $classHourDefs[$id]["hours"]) | |
241 return $id; | |
242 } | |
243 } | |
244 return 0; | |
245 } | |
246 | |
247 | |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
248 // Check given parameters |
87
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
249 // Language must be the first setting to be validated, |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
250 // so that the translation support works properly. |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
251 if (isset($_GET["lang"])) |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
252 { |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
253 $tmp = strtolower($_GET["lang"]); |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
254 if (in_array($tmp, $pageLanguages)) |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
255 { |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
256 $pageLang = $tmp; |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
257 setcookie("luklang", $tmp, time() + 365*24*60*60); // expire in a year |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
258 } |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
259 } |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
260 else |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
261 if (isset($_COOKIE["luklang"])) |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
262 { |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
263 $tmp = $_COOKIE["luklang"]; |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
264 if (in_array($tmp, $pageLanguages)) |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
265 $pageLang = $tmp; |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
266 } |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
267 |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
268 |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
269 // Check if we are using mobile mode |
83 | 270 $mobileMode = FALSE; |
88
d78a063b2053
Disable mobile mode in the main branch for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
271 /* |
83 | 272 if (isset($_GET["m"])) |
273 { | |
274 $mobileMode = intval($_GET["m"]); | |
275 setcookie("lukmobile", $mobileMode, time() + 365*24*60*60); // expire in a year | |
276 } | |
277 else | |
278 if (isset($_COOKIE["lukmobile"])) | |
279 { | |
280 $mobileMode = $_COOKIE["lukmobile"]; | |
281 } | |
282 | |
283 if ($mobileMode) | |
284 { | |
285 $pageCSSData["prefix"] = $baseURI."mluk"; | |
286 } | |
88
d78a063b2053
Disable mobile mode in the main branch for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
287 */ |
82
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
288 |
87
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
289 // Check class setting |
59 | 290 if (isset($_GET["luokka"])) |
291 { | |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
292 $luokka = $_GET["luokka"]; |
66
6315df2faeec
Remove a lingering miniMode variable check.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
293 if (lukCheckClassID($luokka)) |
59 | 294 { |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
295 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
|
296 } |
59 | 297 } |
298 else | |
299 if (isset($_COOKIE["lukluokka"])) | |
300 { | |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
301 $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
|
302 lukCheckClassID($luokka); |
59 | 303 } |
304 else | |
305 { | |
63 | 306 errorMsg(lukMsg("classNotSet", $classDefault)); |
307 $luokka = $classDefault; | |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
308 } |
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
309 |
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
310 |
87
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
311 // Check next period flag |
59 | 312 if (isset($_GET["next"])) |
313 { | |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
314 $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
|
315 $cachePath = "cache-next/"; |
59 | 316 } |
317 else | |
318 { | |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
319 $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
|
320 $cachePath = "cache/"; |
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
321 } |
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
322 |
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
323 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
|
324 { |
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
325 require $cachePath."baseuri.data"; |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
326 } |
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
327 |
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
328 |
1 | 329 // Global cache for course data |
330 $cache = array(); | |
331 $cacheDirty = FALSE; | |
332 | |
333 // 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
|
334 $fp = @fopen($courseCacheFile, "rb"); |
59 | 335 if ($fp) |
336 { | |
337 if (flock($fp, LOCK_SH)) | |
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 require($courseCacheFile); |
1 | 340 flock($fp, LOCK_UN); |
341 } | |
342 fclose($fp); | |
343 } | |
344 | |
43
7621bfc47491
Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
345 |
28 | 346 // Read classfile |
59 | 347 $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
|
348 $fp = @fopen($classIDFile, "rb"); |
59 | 349 if ($fp) |
350 { | |
351 if (flock($fp, LOCK_SH)) | |
352 { | |
353 while (!feof($fp)) | |
354 { | |
5 | 355 $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
|
356 if (strlen($str) > 2 && $str[0] != "#") |
5 | 357 $classes[] = $str; |
358 } | |
359 flock($fp, LOCK_UN); | |
360 } | |
361 fclose($fp); | |
59 | 362 } |
363 else | |
364 { | |
44
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
365 errorMsg("Luokkien listaa ei löytynyt. Kokeile ladata sivu uudelleen hetken kuluttua."); |
1 | 366 } |
367 | |
368 | |
82
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
369 $dataFile = $cachePath.$luokka.".data"; |
59 | 370 if (!file_exists($dataFile)) |
371 { | |
89
f9cd4c5ca3d6
Translate one more error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
372 errorMsg(lukMsg("classDataNotFound", lukChEntities($luokka))); |
5 | 373 $haveData = FALSE; |
1 | 374 } |
59 | 375 else |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
376 { |
59 | 377 require($dataFile); |
378 $haveData = isset($classInfo); | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
379 } |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
380 |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
381 |
83 | 382 function lukPrintTimeTable($mini) |
59 | 383 { |
63 | 384 global $classInfo, $classHourDefs, $classHourTimes; |
20 | 385 |
71
0329105ddedc
Fix grouped + active state display.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
386 // $currStamp = time() + ((3 * 60) + 45) * 60; |
59 | 387 $currStamp = time(); |
388 $currTime = $currStamp - mktime(0, 0, 0); | |
63 | 389 $currDay = lukGetWeekdayFromTimestamp($currStamp); |
79
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
390 |
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
391 $nextStamp = $currStamp + 30 * 60; |
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
392 $nextTime = $nextStamp - mktime(0, 0, 0); |
59 | 393 |
5 | 394 // Create the timetable table |
83 | 395 if ($mini) |
396 { | |
397 $out = | |
398 "<table class=\"timetable\">". | |
399 " <tr>\n <th></th>". | |
400 " <th class=\"days\">".lukGetDayName($currDay)."</th>\n </tr>\n"; | |
401 | |
402 $startDay = $currDay; | |
403 $lastDay = $currDay + 1; | |
404 } | |
405 else | |
59 | 406 { |
83 | 407 $out = |
408 "<p>".join("; ", $classInfo["general"])."</p>\n". | |
409 "<div>".lukMsg("viikossa", $classInfo["totalHours"])."</div>\n". | |
410 "<table class=\"timetable\">". | |
411 " <tr>\n <th></th>\n"; | |
91 | 412 |
413 $cellWidth = $classInfo["maxDays"] > 0 ? 100 / $classInfo["maxDays"] : 15; | |
83 | 414 if ($cellWidth > 25) $cellWidth = 25; |
415 | |
416 for ($day = 0; $day < $classInfo["maxDays"]; $day++) | |
417 { | |
418 $out .= " <th style=\"width: ".$cellWidth."%;\" class=\"days\">".lukGetDayName($day)."</th>\n"; | |
419 } | |
420 $out .= " </tr>\n"; | |
421 $startDay = 0; | |
422 $lastDay = $classInfo["maxDays"]; | |
5 | 423 } |
83 | 424 |
1 | 425 |
59 | 426 for ($hour = $classInfo["firstHour"]; $hour < $classInfo["lastHour"]; $hour++) |
427 { | |
44
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
428 $out .= " <tr>\n". |
59 | 429 " <th class=\"hours\">".lukGetHourStr($hour)."</th>\n"; |
83 | 430 for ($day = $startDay; $day < $lastDay; $day++) |
59 | 431 { |
432 $id = lukFindClass($day, $hour); | |
433 if ($id > 0) | |
434 { | |
435 $class = &$classHourDefs[$id]; | |
436 if (!isset($class["set"])) | |
437 { | |
438 $class["set"] = TRUE; | |
439 | |
83 | 440 $nextActive = $day == $currDay && |
79
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
441 $nextTime >= $classHourTimes[$class["start"]]["start"] && |
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
442 $nextTime < $classHourTimes[$class["start"] + $class["hours"] - 1]["end"]; |
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
443 |
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
444 $isActive = $day == $currDay && |
59 | 445 $currTime >= $classHourTimes[$class["start"]]["start"] && |
446 $currTime < $classHourTimes[$class["start"] + $class["hours"] - 1]["end"]; | |
447 | |
79
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
448 $out .= " <td rowspan=\"".$class["hours"]."\" class=\"". |
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
449 ($isActive ? "clactive " : ""). |
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
450 (!$isActive && $nextActive ? "clnext " : ""). |
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
451 ($class["grouped"] ? "clgrouped" : "clnormal")."\">". |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
452 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
|
453 "<div class=\"nhours\"><span>".$class["hours"]."h</span></div></td>\n"; |
59 | 454 } |
455 } | |
456 else | |
457 { | |
458 $out .= " <td class=\"clnothing\"></td>\n"; | |
459 } | |
44
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
460 } |
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
461 $out .= " </tr>\n"; |
1 | 462 } |
463 | |
59 | 464 return $out."</table>\n"; |
465 } | |
5 | 466 |
467 | |
59 | 468 // |
469 // | |
470 // | |
5 | 471 $pageTitle = $haveData ? $luokka." / ".join("; ", $classInfo["info"]) : $luokka; |
472 printPageHeader($pageTitle); | |
18 | 473 |
59 | 474 echo "<form id=\"controls\" action=\"".$baseURI."\" method=\"get\"> |
30 | 475 <table> |
476 <tr> | |
45
d8a1e85b8dda
Change the visual style a tiny bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
477 <th> |
30 | 478 <select name=\"luokka\"> |
479 "; | |
5 | 480 |
481 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
|
482 echo " <option ".($luokka == $class ? "selected=\"selected\" " : "")."value=\"".$class."\">".lukChEntities($class)."</option>\n"; |
1 | 483 } |
30 | 484 echo |
485 " </select> | |
45
d8a1e85b8dda
Change the visual style a tiny bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
486 </th> |
63 | 487 <th><input class=\"submit\" type=\"submit\" value=\"".lukMsg("Switch")."\" /></th> |
83 | 488 "; |
17 | 489 |
83 | 490 if (!$mobileMode) |
491 { | |
96 | 492 echo |
493 " <th><a id=\"next\" class=\"textctrl\" href=\"".$baseURI.($nextPeriod ? "" : "?next")."\">". | |
494 ($nextPeriod ? lukMsg("Current period") : lukMsg("Next period"))."</a></th>\n". | |
495 " <th><a id=\"orig\" class=\"textctrl\" href=\"".$origBaseURI.$luokka.$origBaseExt."\">".lukMsg("Original")."</a></th>\n". | |
496 " <th><a id=\"xml\" class=\"textctrl\" href=\"".$baseURI.$cachePath."/".$luokka.".xml\">XML</a></th>\n". | |
497 " <th><a class=\"textctrl mobile\" href=\"http://tnsp.org/mluk/\">Mobile</a></th>\n"; | |
83 | 498 } |
78 | 499 |
96 | 500 echo |
501 " </tr>\n". | |
502 " </table>\n". | |
503 "</form>\n". | |
504 "<h1>".$pageTitle."</h1>\n"; | |
1 | 505 |
506 // Show error messages | |
59 | 507 if ($errorSet) |
508 { | |
1 | 509 echo "<ul>\n"; |
44
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
510 foreach ($errorMsgs as $msg) |
1 | 511 echo "<li>$msg</li>\n"; |
512 echo "</ul>\n"; | |
513 } | |
514 | |
59 | 515 if ($haveData) |
516 { | |
83 | 517 echo lukPrintTimeTable($mobileMode); |
59 | 518 } |
5 | 519 |
73 | 520 echo |
521 "<div id=\"footer\">". | |
522 lukMsg("contact", "ccr @ IRCNet", "ccr (at) tnsp (dot) org"). | |
93 | 523 //" <div style=\"color: red;\">".lukMsg("beta")."</div>\n". |
524 "</div>\n"; | |
84 | 525 |
526 if (!$mobileMode) | |
527 { | |
92 | 528 echo "<div id=\"csssel\">\n". |
529 " <div id=\"ctitle\">Lukkari v2.0</div>\n". | |
530 " <div>".lukMsg("Style").": "; | |
63 | 531 |
49
16aea8e5cb71
Improved CSS, added a third stylesheet option.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
532 foreach ($pageCSSAlts as $name => $id) |
69 | 533 echo "<a href=\"".$baseURI."?css=".$id."\">".$name."</a>"; |
63 | 534 |
92 | 535 echo "</div>\n". |
536 " <div id=\"clang\">"; | |
63 | 537 foreach ($pageLanguages as $id) |
69 | 538 echo "<a href=\"".$baseURI."?lang=".$id."\">".$id."</a>"; |
92 | 539 echo "</div>\n"; |
84 | 540 } |
541 | |
92 | 542 echo "</div>\n"; |
1 | 543 printPageFooter(); |
544 | |
545 | |
546 // 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
|
547 if ($cacheDirty) |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
548 { |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
549 $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
|
550 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
|
551 // Can't do much anything here .. |
1 | 552 } |
553 } | |
554 | |
555 ?> |