Mercurial > hg > lukkari
annotate index.php @ 37:3ba4feff55cb
Partially convert to UTF-8.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 08 Mar 2012 07:25:01 +0200 |
parents | dbe7ff545293 |
children | 2195ede068c8 |
rev | line source |
---|---|
1 | 1 <? |
2 $pageCSS = array("http://tnsp.org/docs1.css", "luk.css"); | |
3 $pageCharset = "iso-8859-15"; | |
4 $luokkaDefault = "TTE9SNO"; | |
5 | 5 $dataDir = "cache/"; |
6 $classFile = "luokat.txt"; | |
1 | 7 $mapFile = "kartta.png"; |
5 | 8 $roomFile = "luokkatilat.txt"; |
1 | 9 $cacheFile = "coursecache.txt"; |
16
ea9558465ad6
Add link to original data, fix left-over beta stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
10 $baseURI = "http://tnsp.org/luk/"; |
30 | 11 //$infoURI = "http://www.oamk.fi/opiskelijalle/rakenne/opinto-opas/koulutusohjelmat/?sivu=oj&kieli=FI&opas=2010-2011&vuosi=10S11K&koodi1="; |
12 $infoURI = "http://www.oamk.fi/opiskelijalle/rakenne/opinto-opas/koulutusohjelmat/?sivu=oj&kieli=FI&koodi1="; | |
1 | 13 $dayNames = array("Maanantai", "Tiistai", "Keskiviikko", "Torstai", "Perjantai", "Lauantai", "Sunnuntai"); |
14 | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
15 $hourStamps = array( |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
16 array( 8, 15), |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
17 array( 9, 15), |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
18 array(10, 15), |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
19 array(11, 15), |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
20 array(12, 15), |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
21 array(13, 15), |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
22 array(14, 15), |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
23 array(15, 15), |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
24 array(16, 15), |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
25 array(17, 5), |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
26 array(18, 5), |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
27 array(19, 0), |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
28 array(20, 45), |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
29 ); |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
30 |
5 | 31 // Include framework |
1 | 32 require "mcommon.inc.php"; |
33 require "merrors.inc.php"; | |
34 | |
2 | 35 |
5 | 36 // Helper functions |
1 | 37 function checkClassID(&$id) |
38 { | |
39 global $luokkaDefault; | |
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
|
40 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
|
41 $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
|
42 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
|
43 } else { |
37 | 44 errorMsg("Virhe! Luokan täytyy olla muotoa <b>XXXnXXX</b>, käytetään vakioarvoa <b>".$luokkaDefault."</b>."); |
1 | 45 $id = $luokkaDefault; |
46 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
|
47 } |
1 | 48 } |
49 | |
17 | 50 // Check for mini-info mode |
51 $miniMode = isset($_GET["nyt"]); | |
1 | 52 |
53 // Check given parameters | |
54 if (isset($_GET["luokka"])) { | |
55 $luokka = $_GET["luokka"]; | |
17 | 56 if (checkClassID($luokka) && !$miniMode) { |
1 | 57 setcookie("lukluokka", $luokka, time() + 365*24*60*60); // expire in a year |
58 } | |
59 } else | |
60 if (isset($_COOKIE["lukluokka"])) { | |
61 $luokka = $_COOKIE["lukluokka"]; | |
62 checkClassID($luokka); | |
63 } else { | |
64 errorMsg("Luokkaa ei asetettu, käytetään vakioarvoa <b>".$luokkaDefault."</b>."); | |
65 $luokka = $luokkaDefault; | |
66 } | |
67 | |
68 | |
69 if (isset($_GET["tila"])) { | |
70 $tila = $_GET["tila"]; | |
71 echo "Luokkatilan näyttömoodi ei vielä tuettu.<br />\n"; | |
72 exit; | |
73 | |
5 | 74 $fp = @fopen($roomFile, "rb"); |
1 | 75 if ($fp) { |
76 fclose($fp); | |
77 } | |
78 } | |
79 | |
20 | 80 |
81 function getHourStamp($hour, $sec = 0, $mon = 0, $day = 0, $year = 0) | |
5 | 82 { |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
83 global $hourStamps; |
17 | 84 if (isset($hourStamps[$hour])) |
20 | 85 return mktime($hourStamps[$hour][0], $hourStamps[$hour][1], $sec, $mon, $year); |
17 | 86 else |
20 | 87 return mktime($hour + 8, 0, $sec, $mon, $year); |
88 } | |
89 | |
17 | 90 |
20 | 91 function getHour($hour) |
92 { | |
93 $stamp = getHourStamp($hour); | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
94 return "<br />".date("H:i", $stamp)." - ".date("H:i", $stamp + 45 * 60)."<br /><br />"; |
5 | 95 } |
96 | |
97 | |
1 | 98 function matchCourse($id) |
99 { | |
100 global $cache, $infoURI, $cacheDirty; | |
101 | |
102 // Check if course exists in cache | |
103 if (!isset($cache[$id])) { | |
104 $cacheDirty = TRUE; | |
105 // Not cached, try to fetch data | |
106 $data = @file_get_contents($infoURI.$id); | |
107 if ($data !== FALSE) { | |
108 if (preg_match("#<td class=\"smallheadercell\"><strong>(.+?)\s+(\d+)\s*op\s*</strong></td>#", $data, $m)) { | |
109 // Add data to cache | |
110 $cache[$id] = array("desc" => $m[1], "op" => intval($m[2])); | |
111 } | |
112 } | |
113 } | |
114 | |
115 if (isset($cache[$id])) | |
116 return "<a target=\"_blank\" title=\"".htmlentities($id." - ".$cache[$id]["op"]." op"). | |
117 "\" href=\"".htmlentities($infoURI.$id)."\">".htmlentities($cache[$id]["desc"])."</a>"; | |
118 else | |
119 return htmlentities($id); | |
120 } | |
121 | |
122 | |
123 function matchClass($matches) | |
124 { | |
125 global $baseURI; | |
5 | 126 return "<b><a href=\"".$baseURI."?tila=".$matches[1]."\">".$matches[1]."</a></b> ".$matches[2]; |
1 | 127 } |
128 | |
129 | |
130 // Global cache for course data | |
131 $cache = array(); | |
132 $cacheDirty = FALSE; | |
133 | |
134 | |
135 // Try to read cachefile, if we can get file lock on it | |
136 $fp = @fopen($cacheFile, "rb"); | |
137 if ($fp) { | |
138 if (flock($fp, LOCK_SH)) { | |
139 require($cacheFile); | |
140 flock($fp, LOCK_UN); | |
141 } | |
142 fclose($fp); | |
143 } | |
144 | |
28 | 145 // Read classfile |
5 | 146 $fp = @fopen($classFile, "rb"); |
147 $classes = array(); | |
148 if ($fp) { | |
149 if (flock($fp, LOCK_SH)) { | |
150 while (!feof($fp)) { | |
151 $str = trim(fgets($fp, 128)); | |
152 if ($str[0] != "#" && strlen($str) > 2) | |
153 $classes[] = $str; | |
154 } | |
155 flock($fp, LOCK_UN); | |
156 } | |
157 fclose($fp); | |
17 | 158 } else { |
37 | 159 errorMsg("Luokkien listaa ei löytynyt. Kokeile ladata sivu uudelleen hetken kuluttua."); |
1 | 160 } |
161 | |
31
dbe7ff545293
Add support for fetching and showing data for next/upcoming period.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
162 if (isset($_GET["next"])) |
dbe7ff545293
Add support for fetching and showing data for next/upcoming period.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
163 $dataFile = "cache-next/".$luokka.".data"; |
dbe7ff545293
Add support for fetching and showing data for next/upcoming period.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
164 else |
dbe7ff545293
Add support for fetching and showing data for next/upcoming period.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
165 $dataFile = "cache/".$luokka.".data"; |
1 | 166 |
31
dbe7ff545293
Add support for fetching and showing data for next/upcoming period.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
167 if (!file_exists($dataFile)) { |
17 | 168 errorMsg("Luokan ".htmlentities($luokka)." tietoja ei löytynyt! Jos luokkakoodi on uusi, ilmestyy se järjestelmään seuraavan päivityksen aikana. Luokkatiedot päivitetään 2 kertaa vuorokaudessa."); |
5 | 169 $haveData = FALSE; |
170 } else { | |
31
dbe7ff545293
Add support for fetching and showing data for next/upcoming period.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
171 require($dataFile); |
5 | 172 $haveData = isset($classDefs); |
1 | 173 } |
174 | |
5 | 175 |
176 function printHourInfo($dayHours, $showDays) | |
177 { | |
37 | 178 $out = " <tr>\n <td>Tunteja<br />(<b>ryhmä/vv</b>)</td>\n"; |
5 | 179 for ($day = 0; $day < $showDays; $day++) { |
180 $out .= " <td>".$dayHours[$day]["total"]."h (<b>".$dayHours[$day]["grouped"]."h</b>)</td>\n"; | |
181 } | |
182 return $out." </tr>\n"; | |
1 | 183 } |
184 | |
185 | |
12
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
186 function findHours($start, $day, $cmp, $mark = FALSE) |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
187 { |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
188 global $classHourTable, $classInfo; |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
189 $n = 0; |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
190 for ($i = $start; $i < $classInfo["maxhours"]; $i++) |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
191 if ($classHourTable[$i][$day] == $cmp) { |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
192 if ($mark) $classHourTable[$i][$day] = -9999; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
193 $n++; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
194 } else |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
195 break; |
12
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
196 return $n; |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
197 } |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
198 |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
199 |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
200 function findNextHour(&$j, &$i, $day, $hour, $chk) |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
201 { |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
202 global $classInfo, $classHourTable; |
20 | 203 // for ($j = $day; $j < $classInfo["maxdays"]; $j++) |
204 $j = $day; | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
205 for ($i = $hour; $i < $classInfo["maxhours"]; $i++) { |
20 | 206 if ($chk > 0 && $classHourTable[$i][$j] != $chk) |
207 return $classHourTable[$i][$j]; | |
208 | |
209 if ($classHourTable[$i][$j] > 0 && $classHourTable[$i][$j] != $chk) | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
210 return $classHourTable[$i][$j]; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
211 } |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
212 |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
213 return -1; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
214 } |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
215 |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
216 |
19 | 217 function getHourInfo($isSplit, $d) |
218 { | |
219 if ($isSplit) { | |
220 $out = "<table>". | |
221 "<tr><td>".matchCourse($d[0])."</td><td>".matchCourse($d[1])."</td></tr>"; | |
222 | |
223 for ($j = 2; $j < count($d); $j += 2) | |
224 $out .= "<tr><td>".htmlentities($d[$j])."</td><td>".(isset($d[$j+1]) ? htmlentities($d[$j+1]) : "")."</td></tr>"; | |
225 | |
226 return $out."</table>"; | |
227 } else { | |
228 $out = matchCourse($d[0])."<br />"; | |
229 | |
230 for ($j = 1; $j < count($d); $j++) | |
231 $out .= htmlentities($d[$j])."<br />"; | |
232 | |
233 return $out; | |
234 } | |
235 } | |
236 | |
237 | |
238 function getHourInfoData($id) | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
239 { |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
240 global $classDefs; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
241 |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
242 if (isset($id)) { |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
243 if ($id >= 0 && isset($classDefs[$id])) { |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
244 $i = $classDefs[$id]; |
19 | 245 $isSplit = preg_match("/^[A-Z]\d{6}$/", $i["data"][1]); |
246 return getHourInfo($isSplit, $i["data"]); | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
247 } else |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
248 return "<p>Ei tunteja.</p>"; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
249 } else |
37 | 250 return "<p>Ei mitään.</p>"; |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
251 |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
252 return ""; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
253 } |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
254 |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
255 |
17 | 256 if ($miniMode) { |
20 | 257 $stamp = time(); |
258 $aika = getdate($stamp); | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
259 $day = $aika["wday"] - 1; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
260 if ($day < 0) $day = 7; |
20 | 261 $hour = $aika["hours"] - 8; |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
262 |
20 | 263 $id = $classHourTable[$hour][$day]; |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
264 |
18 | 265 $out = "<div class=\"content\">\n". |
20 | 266 "<h2>".$dayNames[$day]." ".date("d.n.Y", $stamp)." - klo ".date("H:i", $stamp)."</h2>\n". |
267 getHourInfoData($id)."\n"; | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
268 |
20 | 269 |
270 if (isset($id) && $id >= 0 && isset($classDefs[$id])) { | |
271 $i = $classDefs[$id]; | |
272 $start = getHourStamp($i["start"]); | |
273 } | |
274 | |
275 // echo "day=$day, hour=$hour, id=$id<br />\n"; | |
276 | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
277 if ($day >= $classInfo["maxdays"]) { |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
278 $day = $hour = 0; |
20 | 279 $id = -1; |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
280 } else |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
281 if ($hour < 0) { |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
282 $hour = 0; |
20 | 283 $id = -1; |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
284 } else |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
285 if ($hour >= $classInfo["maxhours"]) { |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
286 $day++; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
287 $hour = 0; |
20 | 288 $id = -1; |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
289 } |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
290 |
20 | 291 // echo "day=$day, hour=$hour, id=$id<br />\n"; |
292 $found = findNextHour($nday, $nhour, $day, $hour, $id); | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
293 |
20 | 294 // echo "nday=$nday, nhour=$nhour, id=$found<br />\n"; |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
295 |
20 | 296 $out .= "<h2>Seuraavaksi"; |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
297 if ($found > 0) { |
20 | 298 $stamp = getHourStamp($nhour, 0, 0, $aika["mon"], $aika["mday"] + $nday - $day, $aika["year"]); |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
299 $aika = getdate($stamp); |
20 | 300 $out .= ": ".$dayNames[$nday]." ".date("d.n.Y", $stamp)." - klo ".date("H:i", $stamp)."</h2>\n". |
301 getHourInfoData($found)."\n"; | |
302 } else { | |
303 $out .= "</h2>\n". | |
37 | 304 "<p>Ei mitään</p>\n"; |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
305 } |
20 | 306 |
307 $out .= "</div>\n"; | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
308 } |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
309 else |
5 | 310 if ($haveData) { |
311 $totalHours = 0; | |
312 $totalGrouped = 0; | |
313 $dayHours = array(); | |
7 | 314 |
11 | 315 for ($day = 0; $day < $classInfo["maxdays"]; $day++) { |
5 | 316 $dayHours[$day]["total"] = $dayHours[$day]["grouped"] = 0; |
1 | 317 |
11 | 318 for ($hour = 0; $hour < $classInfo["maxhours"]; $hour++) { |
319 $id = $classHourTable[$hour][$day]; | |
1 | 320 |
11 | 321 if ($id > 0) { |
322 $totalHours++; | |
323 $dayHours[$day]["total"]++; | |
324 | |
325 if ($classDefs[$id]["grouped"]) { | |
326 $totalGrouped++; | |
327 $dayHours[$day]["grouped"]++; | |
328 } | |
329 } | |
5 | 330 } |
331 } | |
332 | |
333 // Create the timetable table | |
334 $out = | |
335 "<p>".join("; ", $classInfo["general"])."</p>\n". | |
37 | 336 "<div>Viikossa yhteensä <b>".$totalHours."</b> tuntia, joista <b>".$totalGrouped."</b> ryhmissä tai vuoroviikoin.</div>\n". |
5 | 337 "<table class=\"timetable\">". |
338 " <tr>\n <th></th>\n"; | |
7 | 339 for ($day = 0; $day < $classInfo["maxdays"]; $day++) { |
18 | 340 $out .= " <th style=\"width: ".(100 / $classInfo["maxdays"]). |
341 "%;\" class=\"days\">".$dayNames[$day]."</th>\n"; | |
5 | 342 } |
343 $out .= " </tr>\n"; | |
1 | 344 |
345 for ($hour = 0; $hour < $classInfo["maxhours"]; $hour++) { | |
5 | 346 $out .= " <tr>\n". |
347 " <th class=\"hours\">".getHour($hour)."</th>\n"; | |
7 | 348 for ($day = 0; $day < $classInfo["maxdays"]; $day++) { |
1 | 349 if (isset($classHourTable[$hour][$day])) { |
350 $h = $classHourTable[$hour][$day]; | |
351 | |
352 if ($h < 1) { | |
10
6272ca0cacea
Make editing of custom timetable easier.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
353 if ($h > -9999) { |
12
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
354 $n = findHours($hour, $day, $h, TRUE); |
5 | 355 $out .= " <td rowspan=\"".$n."\" class=\"clnothing\"></td>\n"; |
1 | 356 } |
357 } else | |
358 if (isset($classDefs[$h])) { | |
359 if (!isset($classDefs[$h]["done"])) { | |
360 $classDefs[$h]["done"] = true; | |
361 $i = $classDefs[$h]; | |
362 $d = $classDefs[$h]["data"]; | |
363 | |
364 $isSplit = preg_match("/^[A-Z]\d{6}$/", $d[1]); | |
365 | |
12
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
366 $hours = findHours($hour, $day, $h, FALSE); |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
367 if ($hours != $i["hours"]) { |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
368 errorMsg("Internal error, cell $hour / $day : hour id $h hours ($hours) do not match ".$i["hours"]."!"); |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
369 } |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
370 |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
371 $out .= " <td rowspan=\"".$hours. |
19 | 372 "\" class=\"".($isSplit || $i["grouped"] ? "clgrouped" : "clnormal")."\">". |
373 getHourInfo($isSplit, $d). | |
374 "<div class=\"nhours\"><span>".$hours."h</span></div></td>\n"; | |
1 | 375 } |
376 } else | |
377 errorMsg("Internal error cell $hour / $day : hour id $h does not exist!"); | |
378 } else | |
379 errorMsg("Internal error, cell $hour / $day does not exist."); | |
380 } | |
5 | 381 $out .= " </tr>\n"; |
1 | 382 } |
383 | |
7 | 384 $out .= printHourInfo($dayHours, $classInfo["maxdays"]). |
14 | 385 "</table>\n"; |
5 | 386 |
387 } // haveData | |
388 | |
389 | |
390 $pageTitle = $haveData ? $luokka." / ".join("; ", $classInfo["info"]) : $luokka; | |
391 printPageHeader($pageTitle); | |
18 | 392 |
393 if ($miniMode) echo "<div id=\"mini\">\n"; | |
5 | 394 |
18 | 395 echo |
30 | 396 "<form id=\"controls\" action=\"".$baseURI."\" method=\"get\"> |
397 <table> | |
398 <tr> | |
399 <td> | |
400 <select name=\"luokka\"> | |
401 "; | |
5 | 402 |
403 foreach ($classes as $class) { | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
404 echo " <option ".($luokka == $class ? "selected=\"selected\" " : "")."value=\"".$class."\">".htmlentities($class)."</option>\n"; |
1 | 405 } |
30 | 406 echo |
407 " </select> | |
408 </td> | |
409 <td><input type=\"submit\" value=\" Vaihda \" /></td> | |
410 <td>[<a href=\"".$baseURI."?luokka=".$luokka; | |
17 | 411 |
412 if ($miniMode) | |
413 echo "\">Normaali"; | |
414 else | |
415 echo "&nyt\">Mini-info"; | |
416 | |
30 | 417 echo "</a>]</td> |
418 <td>[<a href=\"http://www.oamk.fi/tyojarjestykset/otek/luokat/OR_".$luokka.".htm\">Alkuperäinen</a>]</td> | |
31
dbe7ff545293
Add support for fetching and showing data for next/upcoming period.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
419 <td>[<a href=\"".$baseURI."?next\">Seuraava periodi</a>]</td> |
30 | 420 </tr> |
421 </table> | |
422 </form> | |
423 "; | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
424 |
18 | 425 echo "<h1>".$pageTitle."</h1>\n"; |
1 | 426 |
427 // Show error messages | |
428 if ($errorSet) { | |
429 echo "<ul>\n"; | |
430 foreach ($errorMsgs as $msg) | |
431 echo "<li>$msg</li>\n"; | |
432 echo "</ul>\n"; | |
433 } | |
434 | |
5 | 435 echo $out; |
436 | |
28 | 437 echo "<div style=\"position: relative; top: 5em; font-size: 5pt;\"><hr /> |
37 | 438 Yhteydenotot <b>ccr @ IRCNet</b> tai <b>ccr at tnsp dot org</b>. En vastaa mahdollisista virheistä tiedoissa! |
30 | 439 </div> |
440 "; | |
18 | 441 |
442 if ($miniMode) echo "</div>\n"; | |
1 | 443 printPageFooter(); |
444 | |
445 | |
446 // Dump the course data cache, but only if it has changed | |
447 if ($cacheDirty) { | |
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
|
448 // Create string containing the data |
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
|
449 $str = "<?\n\$cache = array(\n"; |
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
|
450 foreach ($cache as $id => $data) { |
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
|
451 $str .= " \"".addslashes($id)."\" => array(\"desc\" => \"". |
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
|
452 addslashes($data["desc"])."\", \"op\" => ".$data["op"]."),\n"; |
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
|
453 } |
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
|
454 $str .= ");\n?>"; |
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
|
455 |
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
|
456 // Use locking to prevent concurrent access and dump data |
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
|
457 if (file_put_contents($cacheFile, $str, LOCK_EX) === FALSE) { |
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
|
458 // Can't do much anything here .. |
1 | 459 } |
460 } | |
461 | |
462 ?> |