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