Mercurial > hg > lukkari
annotate index.php @ 30:6148ce4a83ed
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 27 Sep 2011 10:56:50 +0300 |
parents | ab06d838d916 |
children | dbe7ff545293 |
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 { |
18 | 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 { |
159 errorMsg("Luokkien listaa ei löytynyt. Kokeile ladata sivu uudelleen hetken kuluttua."); | |
1 | 160 } |
161 | |
162 | |
5 | 163 if (!file_exists($dataDir.$luokka.".data")) { |
17 | 164 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 | 165 $haveData = FALSE; |
166 } else { | |
167 require($dataDir.$luokka.".data"); | |
168 $haveData = isset($classDefs); | |
1 | 169 } |
170 | |
5 | 171 |
172 function printHourInfo($dayHours, $showDays) | |
173 { | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
174 $out = " <tr>\n <td>Tunteja<br />(<b>ryhmä/vv</b>)</td>\n"; |
5 | 175 for ($day = 0; $day < $showDays; $day++) { |
176 $out .= " <td>".$dayHours[$day]["total"]."h (<b>".$dayHours[$day]["grouped"]."h</b>)</td>\n"; | |
177 } | |
178 return $out." </tr>\n"; | |
1 | 179 } |
180 | |
181 | |
12
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
182 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
|
183 { |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
184 global $classHourTable, $classInfo; |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
185 $n = 0; |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
186 for ($i = $start; $i < $classInfo["maxhours"]; $i++) |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
187 if ($classHourTable[$i][$day] == $cmp) { |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
188 if ($mark) $classHourTable[$i][$day] = -9999; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
189 $n++; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
190 } else |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
191 break; |
12
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
192 return $n; |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
193 } |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
194 |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
195 |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
196 function findNextHour(&$j, &$i, $day, $hour, $chk) |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
197 { |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
198 global $classInfo, $classHourTable; |
20 | 199 // for ($j = $day; $j < $classInfo["maxdays"]; $j++) |
200 $j = $day; | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
201 for ($i = $hour; $i < $classInfo["maxhours"]; $i++) { |
20 | 202 if ($chk > 0 && $classHourTable[$i][$j] != $chk) |
203 return $classHourTable[$i][$j]; | |
204 | |
205 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
|
206 return $classHourTable[$i][$j]; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
207 } |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
208 |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
209 return -1; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
210 } |
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 |
19 | 213 function getHourInfo($isSplit, $d) |
214 { | |
215 if ($isSplit) { | |
216 $out = "<table>". | |
217 "<tr><td>".matchCourse($d[0])."</td><td>".matchCourse($d[1])."</td></tr>"; | |
218 | |
219 for ($j = 2; $j < count($d); $j += 2) | |
220 $out .= "<tr><td>".htmlentities($d[$j])."</td><td>".(isset($d[$j+1]) ? htmlentities($d[$j+1]) : "")."</td></tr>"; | |
221 | |
222 return $out."</table>"; | |
223 } else { | |
224 $out = matchCourse($d[0])."<br />"; | |
225 | |
226 for ($j = 1; $j < count($d); $j++) | |
227 $out .= htmlentities($d[$j])."<br />"; | |
228 | |
229 return $out; | |
230 } | |
231 } | |
232 | |
233 | |
234 function getHourInfoData($id) | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
235 { |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
236 global $classDefs; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
237 |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
238 if (isset($id)) { |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
239 if ($id >= 0 && isset($classDefs[$id])) { |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
240 $i = $classDefs[$id]; |
19 | 241 $isSplit = preg_match("/^[A-Z]\d{6}$/", $i["data"][1]); |
242 return getHourInfo($isSplit, $i["data"]); | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
243 } else |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
244 return "<p>Ei tunteja.</p>"; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
245 } else |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
246 return "<p>Ei mitään.</p>"; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
247 |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
248 return ""; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
249 } |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
250 |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
251 |
17 | 252 if ($miniMode) { |
20 | 253 $stamp = time(); |
254 $aika = getdate($stamp); | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
255 $day = $aika["wday"] - 1; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
256 if ($day < 0) $day = 7; |
20 | 257 $hour = $aika["hours"] - 8; |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
258 |
20 | 259 $id = $classHourTable[$hour][$day]; |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
260 |
18 | 261 $out = "<div class=\"content\">\n". |
20 | 262 "<h2>".$dayNames[$day]." ".date("d.n.Y", $stamp)." - klo ".date("H:i", $stamp)."</h2>\n". |
263 getHourInfoData($id)."\n"; | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
264 |
20 | 265 |
266 if (isset($id) && $id >= 0 && isset($classDefs[$id])) { | |
267 $i = $classDefs[$id]; | |
268 $start = getHourStamp($i["start"]); | |
269 } | |
270 | |
271 // echo "day=$day, hour=$hour, id=$id<br />\n"; | |
272 | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
273 if ($day >= $classInfo["maxdays"]) { |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
274 $day = $hour = 0; |
20 | 275 $id = -1; |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
276 } else |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
277 if ($hour < 0) { |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
278 $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 >= $classInfo["maxhours"]) { |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
282 $day++; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
283 $hour = 0; |
20 | 284 $id = -1; |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
285 } |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
286 |
20 | 287 // echo "day=$day, hour=$hour, id=$id<br />\n"; |
288 $found = findNextHour($nday, $nhour, $day, $hour, $id); | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
289 |
20 | 290 // 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
|
291 |
20 | 292 $out .= "<h2>Seuraavaksi"; |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
293 if ($found > 0) { |
20 | 294 $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
|
295 $aika = getdate($stamp); |
20 | 296 $out .= ": ".$dayNames[$nday]." ".date("d.n.Y", $stamp)." - klo ".date("H:i", $stamp)."</h2>\n". |
297 getHourInfoData($found)."\n"; | |
298 } else { | |
299 $out .= "</h2>\n". | |
300 "<p>Ei mitään</p>\n"; | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
301 } |
20 | 302 |
303 $out .= "</div>\n"; | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
304 } |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
305 else |
5 | 306 if ($haveData) { |
307 $totalHours = 0; | |
308 $totalGrouped = 0; | |
309 $dayHours = array(); | |
7 | 310 |
11 | 311 for ($day = 0; $day < $classInfo["maxdays"]; $day++) { |
5 | 312 $dayHours[$day]["total"] = $dayHours[$day]["grouped"] = 0; |
1 | 313 |
11 | 314 for ($hour = 0; $hour < $classInfo["maxhours"]; $hour++) { |
315 $id = $classHourTable[$hour][$day]; | |
1 | 316 |
11 | 317 if ($id > 0) { |
318 $totalHours++; | |
319 $dayHours[$day]["total"]++; | |
320 | |
321 if ($classDefs[$id]["grouped"]) { | |
322 $totalGrouped++; | |
323 $dayHours[$day]["grouped"]++; | |
324 } | |
325 } | |
5 | 326 } |
327 } | |
328 | |
329 // Create the timetable table | |
330 $out = | |
331 "<p>".join("; ", $classInfo["general"])."</p>\n". | |
11 | 332 "<div>Viikossa yhteensä <b>".$totalHours."</b> tuntia, joista <b>".$totalGrouped."</b> ryhmissä tai vuoroviikoin.</div>\n". |
5 | 333 "<table class=\"timetable\">". |
334 " <tr>\n <th></th>\n"; | |
7 | 335 for ($day = 0; $day < $classInfo["maxdays"]; $day++) { |
18 | 336 $out .= " <th style=\"width: ".(100 / $classInfo["maxdays"]). |
337 "%;\" class=\"days\">".$dayNames[$day]."</th>\n"; | |
5 | 338 } |
339 $out .= " </tr>\n"; | |
1 | 340 |
341 for ($hour = 0; $hour < $classInfo["maxhours"]; $hour++) { | |
5 | 342 $out .= " <tr>\n". |
343 " <th class=\"hours\">".getHour($hour)."</th>\n"; | |
7 | 344 for ($day = 0; $day < $classInfo["maxdays"]; $day++) { |
1 | 345 if (isset($classHourTable[$hour][$day])) { |
346 $h = $classHourTable[$hour][$day]; | |
347 | |
348 if ($h < 1) { | |
10
6272ca0cacea
Make editing of custom timetable easier.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
349 if ($h > -9999) { |
12
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
350 $n = findHours($hour, $day, $h, TRUE); |
5 | 351 $out .= " <td rowspan=\"".$n."\" class=\"clnothing\"></td>\n"; |
1 | 352 } |
353 } else | |
354 if (isset($classDefs[$h])) { | |
355 if (!isset($classDefs[$h]["done"])) { | |
356 $classDefs[$h]["done"] = true; | |
357 $i = $classDefs[$h]; | |
358 $d = $classDefs[$h]["data"]; | |
359 | |
360 $isSplit = preg_match("/^[A-Z]\d{6}$/", $d[1]); | |
361 | |
12
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
362 $hours = findHours($hour, $day, $h, FALSE); |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
363 if ($hours != $i["hours"]) { |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
364 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
|
365 } |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
366 |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
367 $out .= " <td rowspan=\"".$hours. |
19 | 368 "\" class=\"".($isSplit || $i["grouped"] ? "clgrouped" : "clnormal")."\">". |
369 getHourInfo($isSplit, $d). | |
370 "<div class=\"nhours\"><span>".$hours."h</span></div></td>\n"; | |
1 | 371 } |
372 } else | |
373 errorMsg("Internal error cell $hour / $day : hour id $h does not exist!"); | |
374 } else | |
375 errorMsg("Internal error, cell $hour / $day does not exist."); | |
376 } | |
5 | 377 $out .= " </tr>\n"; |
1 | 378 } |
379 | |
7 | 380 $out .= printHourInfo($dayHours, $classInfo["maxdays"]). |
14 | 381 "</table>\n"; |
5 | 382 |
383 } // haveData | |
384 | |
385 | |
386 $pageTitle = $haveData ? $luokka." / ".join("; ", $classInfo["info"]) : $luokka; | |
387 printPageHeader($pageTitle); | |
18 | 388 |
389 if ($miniMode) echo "<div id=\"mini\">\n"; | |
5 | 390 |
18 | 391 echo |
30 | 392 "<form id=\"controls\" action=\"".$baseURI."\" method=\"get\"> |
393 <table> | |
394 <tr> | |
395 <td> | |
396 <select name=\"luokka\"> | |
397 "; | |
5 | 398 |
399 foreach ($classes as $class) { | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
400 echo " <option ".($luokka == $class ? "selected=\"selected\" " : "")."value=\"".$class."\">".htmlentities($class)."</option>\n"; |
1 | 401 } |
30 | 402 echo |
403 " </select> | |
404 </td> | |
405 <td><input type=\"submit\" value=\" Vaihda \" /></td> | |
406 <td>[<a href=\"".$baseURI."?luokka=".$luokka; | |
17 | 407 |
408 if ($miniMode) | |
409 echo "\">Normaali"; | |
410 else | |
411 echo "&nyt\">Mini-info"; | |
412 | |
30 | 413 echo "</a>]</td> |
414 <td>[<a href=\"http://www.oamk.fi/tyojarjestykset/otek/luokat/OR_".$luokka.".htm\">Alkuperäinen</a>]</td> | |
415 </tr> | |
416 </table> | |
417 </form> | |
418 "; | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
419 |
18 | 420 echo "<h1>".$pageTitle."</h1>\n"; |
1 | 421 |
422 // Show error messages | |
423 if ($errorSet) { | |
424 echo "<ul>\n"; | |
425 foreach ($errorMsgs as $msg) | |
426 echo "<li>$msg</li>\n"; | |
427 echo "</ul>\n"; | |
428 } | |
429 | |
5 | 430 echo $out; |
431 | |
28 | 432 echo "<div style=\"position: relative; top: 5em; font-size: 5pt;\"><hr /> |
433 Yhteydenotot <b>ccr @ IRCNet</b> tai <b>ccr at tnsp dot org</b>. En vastaa mahdollisista virheistä tiedoissa! | |
30 | 434 </div> |
435 "; | |
18 | 436 |
437 if ($miniMode) echo "</div>\n"; | |
1 | 438 printPageFooter(); |
439 | |
440 | |
441 // Dump the course data cache, but only if it has changed | |
442 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
|
443 // 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
|
444 $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
|
445 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
|
446 $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
|
447 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
|
448 } |
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?>"; |
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 |
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 // 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
|
452 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
|
453 // Can't do much anything here .. |
1 | 454 } |
455 } | |
456 | |
457 ?> |