Mercurial > hg > lukkari
annotate index.php @ 108:436aea5bf49f
Cosmetics.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 11 Dec 2013 16:38:32 +0200 |
parents | 9f976ae7a3e2 |
children | 7d77d21873d1 |
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 // |
107
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
7 // Include framework |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
8 require "mcommon.inc.php"; |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
9 |
64
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
10 $pageLang = "fi"; |
38
2195ede068c8
Add chentities() helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
11 $pageCharset = "utf-8"; |
105 | 12 $classDefault = "TTE1SNO"; |
82
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
13 $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
|
14 $courseCacheFile = "coursecache.txt"; |
63 | 15 $baseURI = "http://tnsp.org/luk/"; |
1 | 16 |
48
d41b51cd4ae5
Implement switchable CSS support and a new default style + very minor code
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
17 $pageCSSData = array("cookie" => "lukcss", "prefix" => $baseURI."luk"); |
68
0acf6e16af93
Add another stylesheet, a dark one.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
18 $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
|
19 |
63 | 20 $pageLanguages = array("fi", "en"); |
21 | |
22 $lukDayNames = array( | |
23 "fi" => array("Maanantai", "Tiistai", "Keskiviikko", "Torstai", "Perjantai", "Lauantai", "Sunnuntai"), | |
24 "en" => array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"), | |
25 ); | |
26 | |
98
6a7172b3a841
Update to match the main page API.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
27 $pageTranslations = array( |
63 | 28 "Original" => array("fi" => "Alkuperäinen"), |
100
055c33cba66e
Make the current/next period button a bit clearer ..
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
29 |
055c33cba66e
Make the current/next period button a bit clearer ..
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
30 "Shown" => array("fi" => "Näkyvillä"), |
63 | 31 "Next period" => array("fi" => "Seuraava periodi"), |
32 "Current period" => array("fi" => "Nykyinen periodi"), | |
33 "Switch" => array("fi" => "Vaihda"), | |
34 | |
35 "contact" => array( | |
73 | 36 "en" => "Contact <b>%1</b> tai <b>%2</b>. The author can't be held responsible for any errors in the data!", |
37 "fi" => "Yhteydenotot <b>%1</b> tai <b>%2</b>. En vastaa mahdollisista virheistä tiedoissa!", | |
63 | 38 ), |
39 | |
103
38e9772901f1
Add in hdd.fi advertisement.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
40 "advert" => array( |
38e9772901f1
Add in hdd.fi advertisement.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
41 "en" => "<a href=\"https://www.hdd.fi/\">hdd.fi - Affordable remote disk space</a>", |
38e9772901f1
Add in hdd.fi advertisement.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
42 "fi" => "<a href=\"https://www.hdd.fi/\">hdd.fi - Edullista etälevytilaa</a>", |
38e9772901f1
Add in hdd.fi advertisement.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
43 ), |
38e9772901f1
Add in hdd.fi advertisement.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
44 |
63 | 45 "beta" => array( |
90
556af969a248
Alter the beta status notice a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
46 "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
|
47 "fi" => " HUOM! Lukkari v2.0 on vielä kehityksen alla. Bugeja voi löytyä.", |
63 | 48 ), |
49 | |
50 "viikossa" => array( | |
51 "en" => "Total of <b>%1</b> hours in the week.", | |
52 "fi" => "Viikossa yhteensä <b>%1</b> tuntia.", | |
53 ), | |
54 | |
55 "classNotSet" => array( | |
56 "en" => "Class not set, using default <b>%1</b>.", | |
57 "fi" => "Luokkaa ei asetettu, käytetään vakioarvoa <b>%1</b>.", | |
58 ), | |
89
f9cd4c5ca3d6
Translate one more error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
59 |
f9cd4c5ca3d6
Translate one more error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
60 "classDataNotFound" => array( |
f9cd4c5ca3d6
Translate one more error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
61 "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
|
62 "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
|
63 "päivitetään kerran viikossa.", |
f9cd4c5ca3d6
Translate one more error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
64 "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
|
65 "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
|
66 "once per week.", |
f9cd4c5ca3d6
Translate one more error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
67 ), |
63 | 68 |
106
e7bd58dec4f3
Update for newer framework, add some translations.
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
69 "classListNotFound" => array( |
e7bd58dec4f3
Update for newer framework, add some translations.
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
70 "fi" => "Luokkien listaa ei löytynyt. Kokeile ladata sivu uudelleen hetken kuluttua.", |
e7bd58dec4f3
Update for newer framework, add some translations.
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
71 "en" => "Class list not found. An update may be in progress, try reloading in a minute.", |
e7bd58dec4f3
Update for newer framework, add some translations.
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
72 ), |
e7bd58dec4f3
Update for newer framework, add some translations.
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
73 |
e7bd58dec4f3
Update for newer framework, add some translations.
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
74 "classFormatError" => array( |
e7bd58dec4f3
Update for newer framework, add some translations.
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
75 "fi" => "Virhe! Luokan täytyy olla muotoa <b>XXXnXXX</b>, käytetään vakioarvoa <b>%1</b>.", |
e7bd58dec4f3
Update for newer framework, add some translations.
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
76 "en" => "Error! Class code must be of format <b>XXXnXXX</b>, using default value of <b>%1</b>.", |
e7bd58dec4f3
Update for newer framework, add some translations.
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
77 ), |
e7bd58dec4f3
Update for newer framework, add some translations.
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
78 |
63 | 79 "Style" => array("fi" => "Tyyli"), |
80 // "" => array("fi" => ), | |
81 ); | |
82 | |
83 | |
84 function lukGetDayName($day) | |
85 { | |
86 global $lukDayNames, $pageLang; | |
87 | |
88 if (isset($lukDayNames[$pageLang]) && isset($lukDayNames[$pageLang][$day])) | |
89 return $lukDayNames[$pageLang][$day]; | |
90 else | |
91 return $lukDayNames["en"][$day]; | |
92 } | |
93 | |
94 | |
43
7621bfc47491
Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
95 function lukCheckClassID(&$id) |
1 | 96 { |
63 | 97 global $classDefault; |
23
b4b86915ae2c
Better input validation for $_GET arguments, thanks to Hjalmarr for pointing out the error.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
98 if (preg_match("#^([A-Z]{3}\d[A-Za-z0-9_]{1,6}|ccr|Ryh_[A-Z]{3}\d[A-Za-z0-9_]{1,6})$#", $id, $m)) { |
b4b86915ae2c
Better input validation for $_GET arguments, thanks to Hjalmarr for pointing out the error.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
99 $id = $m[1]; |
b4b86915ae2c
Better input validation for $_GET arguments, thanks to Hjalmarr for pointing out the error.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
100 return TRUE; |
b4b86915ae2c
Better input validation for $_GET arguments, thanks to Hjalmarr for pointing out the error.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
101 } else { |
106
e7bd58dec4f3
Update for newer framework, add some translations.
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
102 stError(cmQM("classFormatError", $classDefault)); |
63 | 103 $id = $classDefault; |
1 | 104 return FALSE; |
23
b4b86915ae2c
Better input validation for $_GET arguments, thanks to Hjalmarr for pointing out the error.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
105 } |
1 | 106 } |
107 | |
59 | 108 |
63 | 109 function lukGetWeekdayFromTimestamp($stamp) |
59 | 110 { |
111 $info = getdate($stamp); | |
112 $day = $info["wday"]; | |
113 return ($day > 0) ? $day - 1 : $day + 6; | |
114 } | |
115 | |
116 | |
117 function lukGetHourStamp($stamp) | |
5 | 118 { |
59 | 119 return date("H:i", mktime(0, 0, $stamp, 0, 0, 0)); |
120 } | |
121 | |
122 | |
123 function lukGetHourStr($hour) | |
124 { | |
125 global $classHourTimes; | |
126 if (isset($classHourTimes[$hour])) | |
127 { | |
128 return | |
129 "<br />". | |
130 lukGetHourStamp($classHourTimes[$hour]["start"]). | |
131 " - ". | |
132 lukGetHourStamp($classHourTimes[$hour]["end"]). | |
133 "<br /><br />"; | |
134 } | |
17 | 135 else |
59 | 136 return "ERROR"; |
5 | 137 } |
138 | |
139 | |
43
7621bfc47491
Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
140 function lukMatchCourse($id) |
1 | 141 { |
107
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
142 global $cache, $cacheDirty, $pageCharset, $pageLang; |
64
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
143 |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
144 $uri = "http://www.oamk.fi/opiskelijalle/rakenne/opinto-opas/koulutusohjelmat/?sivu=oj&kieli=".strtoupper($pageLang)."&koodi1=".$id; |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
145 |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
146 // Create the index |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
147 if (!isset($cache[$id])) |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
148 $cache[$id] = array(); |
1 | 149 |
150 // Check if course exists in cache | |
64
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
151 if (!isset($cache[$id][$pageLang])) |
59 | 152 { |
153 // Not cached, try to fetch data | |
1 | 154 $cacheDirty = TRUE; |
64
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
155 $data = @file_get_contents($uri); |
59 | 156 if ($data !== FALSE) |
157 { | |
107
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
158 $data = iconv("iso-8859-1", $pageCharset, $data); |
64
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
159 if (preg_match("#<td class=\"smallheadercell\"><strong>(.+?)\s+(\d+)\s*(op|ECTS\s+cr)\s*</strong></td>#", $data, $m)) |
59 | 160 { |
1 | 161 // Add data to cache |
64
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
162 $cache[$id][$pageLang] = array("desc" => $m[1], "op" => intval($m[2])); |
1 | 163 } |
164 } | |
165 } | |
166 | |
64
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
167 if (isset($cache[$id]) && isset($cache[$id][$pageLang])) |
59 | 168 { |
107
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
169 return "<a target=\"_blank\" title=\"".chentities($id." - ".$cache[$id][$pageLang]["op"]." op"). |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
170 "\" href=\"".chentities($uri)."\">".chentities($cache[$id][$pageLang]["desc"])."</a>"; |
59 | 171 } |
1 | 172 else |
107
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
173 return chentities($id); |
1 | 174 } |
175 | |
176 | |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
177 function lukGetClassInfo($grouped, $data) |
59 | 178 { |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
179 if ($grouped) |
59 | 180 { |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
181 $out = "<table><tr>"; |
59 | 182 |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
183 $maxCount = 0; |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
184 foreach ($data as $col) |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
185 { |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
186 $out .= "<td>".lukMatchCourse($col[0])."</td>"; |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
187 if (count($col) > $maxCount) |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
188 $maxCount = count($col); |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
189 } |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
190 $out .= "</tr>"; |
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 for ($i = 1; $i < $maxCount; $i++) |
59 | 193 { |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
194 $out .= "<tr>"; |
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>"; |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
198 if (isset($col[$i])) |
107
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
199 $out .= chentities($col[$i]); |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
200 $out .= "</td>"; |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
201 } |
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
202 $out .= "</tr>"; |
59 | 203 } |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
204 |
59 | 205 return $out."</table>"; |
206 } | |
207 else | |
208 { | |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
209 $out = lukMatchCourse($data[0][0])."<br />"; |
59 | 210 |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
211 for ($i = 1; $i < count($data[0]); $i++) |
59 | 212 { |
107
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
213 $out .= chentities($data[0][$i])."<br />"; |
59 | 214 } |
215 | |
216 return $out; | |
217 } | |
218 } | |
219 | |
220 | |
221 function lukFindClass($day, $hour) | |
222 { | |
223 global $classHourDefs, $classDayTable; | |
224 if (isset($classDayTable[$day])) | |
225 { | |
226 foreach ($classDayTable[$day] as $id) | |
227 { | |
228 if ($hour >= $classHourDefs[$id]["start"] && | |
229 $hour < $classHourDefs[$id]["start"] + $classHourDefs[$id]["hours"]) | |
230 return $id; | |
231 } | |
232 } | |
233 return 0; | |
234 } | |
235 | |
236 | |
107
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
237 function lukReadClassFile($filename) |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
238 { |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
239 // Attempt to open file for reading |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
240 if (($fp = @fopen($filename, "rb")) === false) |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
241 return false; |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
242 |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
243 $classes = FALSE; |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
244 |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
245 // Lock file so that we do not get clashes |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
246 if (flock($fp, LOCK_SH)) |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
247 { |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
248 $classes = array(); |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
249 // Read and parse data |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
250 while (!feof($fp)) |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
251 { |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
252 $str = trim(fgets($fp, 128)); |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
253 if (strlen($str) > 2 && $str[0] != "#") |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
254 $classes[] = $str; |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
255 } |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
256 |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
257 // Release lock |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
258 flock($fp, LOCK_UN); |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
259 } |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
260 |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
261 fclose($fp); |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
262 return $classes; |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
263 } |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
264 |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
265 |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
266 // 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
|
267 // 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
|
268 // 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
|
269 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
|
270 { |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
271 $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
|
272 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
|
273 { |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
274 $pageLang = $tmp; |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
275 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
|
276 } |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
277 } |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
278 else |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
279 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
|
280 { |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
281 $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
|
282 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
|
283 $pageLang = $tmp; |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
284 } |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
285 |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
286 |
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
287 // Check if we are using mobile mode |
83 | 288 $mobileMode = FALSE; |
88
d78a063b2053
Disable mobile mode in the main branch for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
289 /* |
83 | 290 if (isset($_GET["m"])) |
291 { | |
292 $mobileMode = intval($_GET["m"]); | |
293 setcookie("lukmobile", $mobileMode, time() + 365*24*60*60); // expire in a year | |
294 } | |
295 else | |
296 if (isset($_COOKIE["lukmobile"])) | |
297 { | |
298 $mobileMode = $_COOKIE["lukmobile"]; | |
299 } | |
300 | |
301 if ($mobileMode) | |
302 { | |
303 $pageCSSData["prefix"] = $baseURI."mluk"; | |
304 } | |
88
d78a063b2053
Disable mobile mode in the main branch for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
305 */ |
82
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
306 |
87
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
307 // Check class setting |
59 | 308 if (isset($_GET["luokka"])) |
309 { | |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
310 $luokka = $_GET["luokka"]; |
66
6315df2faeec
Remove a lingering miniMode variable check.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
311 if (lukCheckClassID($luokka)) |
59 | 312 { |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
313 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
|
314 } |
59 | 315 } |
316 else | |
317 if (isset($_COOKIE["lukluokka"])) | |
318 { | |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
319 $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
|
320 lukCheckClassID($luokka); |
59 | 321 } |
322 else | |
323 { | |
106
e7bd58dec4f3
Update for newer framework, add some translations.
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
324 stError(cmQM("classNotSet", $classDefault)); |
63 | 325 $luokka = $classDefault; |
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 |
87
8743ff5302ce
Add some comments, check language setting first to have the proper language
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
329 // Check next period flag |
59 | 330 if (isset($_GET["next"])) |
331 { | |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
332 $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
|
333 $cachePath = "cache-next/"; |
59 | 334 } |
335 else | |
336 { | |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
337 $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
|
338 $cachePath = "cache/"; |
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
339 } |
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
340 |
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
341 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
|
342 { |
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
343 require $cachePath."baseuri.data"; |
39
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
344 } |
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
345 |
78d0c1cd7282
Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents:
38
diff
changeset
|
346 |
1 | 347 // Global cache for course data |
348 $cache = array(); | |
349 $cacheDirty = FALSE; | |
350 | |
351 // 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
|
352 $fp = @fopen($courseCacheFile, "rb"); |
59 | 353 if ($fp) |
354 { | |
355 if (flock($fp, LOCK_SH)) | |
356 { | |
82
c553ad61e9c2
Make original data links work for both current and next period mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
357 require($courseCacheFile); |
1 | 358 flock($fp, LOCK_UN); |
359 } | |
360 fclose($fp); | |
361 } | |
362 | |
43
7621bfc47491
Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
363 |
83 | 364 function lukPrintTimeTable($mini) |
59 | 365 { |
63 | 366 global $classInfo, $classHourDefs, $classHourTimes; |
20 | 367 |
71
0329105ddedc
Fix grouped + active state display.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
368 // $currStamp = time() + ((3 * 60) + 45) * 60; |
59 | 369 $currStamp = time(); |
370 $currTime = $currStamp - mktime(0, 0, 0); | |
63 | 371 $currDay = lukGetWeekdayFromTimestamp($currStamp); |
79
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
372 |
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
373 $nextStamp = $currStamp + 30 * 60; |
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
374 $nextTime = $nextStamp - mktime(0, 0, 0); |
59 | 375 |
5 | 376 // Create the timetable table |
83 | 377 if ($mini) |
378 { | |
379 $out = | |
380 "<table class=\"timetable\">". | |
381 " <tr>\n <th></th>". | |
382 " <th class=\"days\">".lukGetDayName($currDay)."</th>\n </tr>\n"; | |
383 | |
384 $startDay = $currDay; | |
385 $lastDay = $currDay + 1; | |
386 } | |
387 else | |
59 | 388 { |
83 | 389 $out = |
390 "<p>".join("; ", $classInfo["general"])."</p>\n". | |
98
6a7172b3a841
Update to match the main page API.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
391 "<div>".cmQM("viikossa", $classInfo["totalHours"])."</div>\n". |
83 | 392 "<table class=\"timetable\">". |
393 " <tr>\n <th></th>\n"; | |
91 | 394 |
395 $cellWidth = $classInfo["maxDays"] > 0 ? 100 / $classInfo["maxDays"] : 15; | |
83 | 396 if ($cellWidth > 25) $cellWidth = 25; |
397 | |
398 for ($day = 0; $day < $classInfo["maxDays"]; $day++) | |
399 { | |
400 $out .= " <th style=\"width: ".$cellWidth."%;\" class=\"days\">".lukGetDayName($day)."</th>\n"; | |
401 } | |
402 $out .= " </tr>\n"; | |
403 $startDay = 0; | |
404 $lastDay = $classInfo["maxDays"]; | |
5 | 405 } |
83 | 406 |
1 | 407 |
59 | 408 for ($hour = $classInfo["firstHour"]; $hour < $classInfo["lastHour"]; $hour++) |
409 { | |
44
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
410 $out .= " <tr>\n". |
59 | 411 " <th class=\"hours\">".lukGetHourStr($hour)."</th>\n"; |
83 | 412 for ($day = $startDay; $day < $lastDay; $day++) |
59 | 413 { |
414 $id = lukFindClass($day, $hour); | |
415 if ($id > 0) | |
416 { | |
417 $class = &$classHourDefs[$id]; | |
418 if (!isset($class["set"])) | |
419 { | |
420 $class["set"] = TRUE; | |
421 | |
83 | 422 $nextActive = $day == $currDay && |
79
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
423 $nextTime >= $classHourTimes[$class["start"]]["start"] && |
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
424 $nextTime < $classHourTimes[$class["start"] + $class["hours"] - 1]["end"]; |
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
425 |
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
426 $isActive = $day == $currDay && |
59 | 427 $currTime >= $classHourTimes[$class["start"]]["start"] && |
428 $currTime < $classHourTimes[$class["start"] + $class["hours"] - 1]["end"]; | |
429 | |
79
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
430 $out .= " <td rowspan=\"".$class["hours"]."\" class=\"". |
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
431 ($isActive ? "clactive " : ""). |
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
432 (!$isActive && $nextActive ? "clnext " : ""). |
7dd647a01fb6
Implement indicator for "next" class.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
433 ($class["grouped"] ? "clgrouped" : "clnormal")."\">". |
72
6fd715063abc
Clean up some parsing operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
434 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
|
435 "<div class=\"nhours\"><span>".$class["hours"]."h</span></div></td>\n"; |
59 | 436 } |
437 } | |
438 else | |
439 { | |
440 $out .= " <td class=\"clnothing\"></td>\n"; | |
441 } | |
44
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
442 } |
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
443 $out .= " </tr>\n"; |
1 | 444 } |
445 | |
59 | 446 return $out."</table>\n"; |
447 } | |
5 | 448 |
449 | |
107
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
450 |
108 | 451 // |
107
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
452 // Main code starts |
59 | 453 // |
107
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
454 |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
455 // Read classfile |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
456 if (($classes = lukReadClassFile($classIDFile)) === false) |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
457 stError(stQM("classListNotFound")); |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
458 |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
459 // Read class data |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
460 $dataFile = $cachePath.$luokka.".data"; |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
461 if (!file_exists($dataFile)) |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
462 { |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
463 stError(cmQM("classDataNotFound", chentities($luokka))); |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
464 $haveData = FALSE; |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
465 } |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
466 else |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
467 { |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
468 require($dataFile); |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
469 $haveData = isset($classInfo); |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
470 } |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
471 |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
472 // Set some variables |
5 | 473 $pageTitle = $haveData ? $luokka." / ".join("; ", $classInfo["info"]) : $luokka; |
107
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
474 |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
475 $extra = ""; |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
476 foreach (array(57 => FALSE, 76 => TRUE, 114 => TRUE, 120 => TRUE, 152 => TRUE) as $iconSize => $addSize) |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
477 { |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
478 $extra .= " <link rel=\"apple-touch-icon\" ". |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
479 ($addSize ? "sizes=\"".$iconSize."x".$iconSize."\" " : ""). |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
480 "href=\"icon-".$iconSize."-precomposed.png\" />\n"; |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
481 } |
18 | 482 |
107
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
483 cmPrintPageHeader($pageTitle, $extra); |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
484 ?> |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
485 <script type="text/javascript"> |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
486 function jsCreateXMLRequest() |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
487 { |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
488 var req; |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
489 if (window.XMLHttpRequest) |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
490 { |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
491 // Modern browsers |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
492 req = new XMLHttpRequest(); |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
493 } |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
494 else |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
495 { |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
496 // Old IE versions |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
497 req = new ActiveXObject("Microsoft.XMLHTTP"); |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
498 } |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
499 return req; |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
500 } |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
501 |
5 | 502 |
107
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
503 function jsSendPOSTRequest(params, success, failure) |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
504 { |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
505 var req = jsCreateXMLRequest(); |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
506 req.open("POST", "ajaks.php", true); |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
507 req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
508 req.setRequestHeader("Content-length", params.length); |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
509 req.setRequestHeader("Connection", "close"); |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
510 req.send(params); |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
511 } |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
512 |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
513 function jsClickAdvert() |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
514 { |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
515 jsSendPOSTRequest("a=HyperSpaceYard&t=DivisionCell"); |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
516 return true; |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
517 } |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
518 </script> |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
519 <? |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
520 |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
521 echo |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
522 "<form id=\"controls\" action=\"".$baseURI."\" method=\"get\">\n". |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
523 " <table>\n". |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
524 " <tr>\n". |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
525 " <th>\n". |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
526 " <select name=\"luokka\">\n"; |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
527 |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
528 foreach ($classes as $class) |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
529 { |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
530 echo |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
531 " <option ".($luokka == $class ? "selected=\"selected\" " : ""). |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
532 "value=\"".$class."\">".chentities($class)."</option>\n"; |
1 | 533 } |
30 | 534 echo |
107
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
535 " </select>\n". |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
536 " </th>\n". |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
537 " <th><input class=\"submit\" type=\"submit\" value=\"".cmQM("Switch")."\" /></th>\n"; |
17 | 538 |
83 | 539 if (!$mobileMode) |
540 { | |
96 | 541 echo |
107
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
542 " <th><a id=\"next\" class=\"textctrl\" href=\"".$baseURI.($nextPeriod ? "" : "?next")."\">". |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
543 cmQM("Shown").": ".($nextPeriod ? cmQM("Next period") : cmQM("Current period")). |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
544 "</a></th>\n". |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
545 " <th><a id=\"orig\" class=\"textctrl\" href=\"".$origBaseURI.$luokka.$origBaseExt."\">".cmQM("Original")."</a></th>\n". |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
546 " <th><a id=\"xml\" class=\"textctrl\" href=\"".$baseURI.$cachePath."/".$luokka.".xml\">XML</a></th>\n". |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
547 " <th><a class=\"textctrl mobile\" href=\"http://tnsp.org/mluk/\">Mobile</a></th>\n"; |
83 | 548 } |
78 | 549 |
96 | 550 echo |
551 " </tr>\n". | |
552 " </table>\n". | |
553 "</form>\n". | |
103
38e9772901f1
Add in hdd.fi advertisement.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
554 "<h1>".$pageTitle."</h1>\n". |
38e9772901f1
Add in hdd.fi advertisement.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
555 "<div class=\"advert\">".cmQM("advert")."</div>\n"; |
1 | 556 |
557 // Show error messages | |
59 | 558 if ($errorSet) |
559 { | |
1 | 560 echo "<ul>\n"; |
44
57af36f0864e
Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
561 foreach ($errorMsgs as $msg) |
1 | 562 echo "<li>$msg</li>\n"; |
563 echo "</ul>\n"; | |
564 } | |
565 | |
59 | 566 if ($haveData) |
567 { | |
83 | 568 echo lukPrintTimeTable($mobileMode); |
59 | 569 } |
5 | 570 |
73 | 571 echo |
107
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
572 "<div id=\"footer\">". |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
573 cmQM("contact", "ccr @ IRCNet", "ccr (at) tnsp (dot) org"). |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
574 //" <div style=\"color: red;\">".cmQM("beta")."</div>\n". |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
575 "</div>\n"; |
84 | 576 |
577 if (!$mobileMode) | |
578 { | |
107
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
579 echo |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
580 "<div id=\"csssel\">\n". |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
581 " <div id=\"ctitle\">Lukkari v2.0</div>\n". |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
582 " <div>".cmQM("Style").": "; |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
583 |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
584 foreach ($pageCSSAlts as $name => $id) |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
585 echo "<a href=\"".$baseURI."?css=".$id."\">".$name."</a>"; |
63 | 586 |
107
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
587 echo |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
588 "</div>\n". |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
589 " <div id=\"clang\">"; |
63 | 590 |
107
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
591 foreach ($pageLanguages as $id) |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
592 echo "<a href=\"".$baseURI."?lang=".$id."\">".$id."</a>"; |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
593 |
9f976ae7a3e2
Reformat, modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
594 echo "</div>\n"; |
84 | 595 } |
596 | |
92 | 597 echo "</div>\n"; |
98
6a7172b3a841
Update to match the main page API.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
598 cmPrintPageFooter(); |
1 | 599 |
600 | |
601 // 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
|
602 if ($cacheDirty) |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
603 { |
6900beff8789
Improve multi-language support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
604 $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
|
605 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
|
606 // Can't do much anything here .. |
1 | 607 } |
608 } | |
609 | |
610 ?> |