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