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