Mercurial > hg > lukkari
annotate index.php @ 19:777791321149
Modularize, cleanup.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 12 Jan 2011 03:06:46 +0200 |
parents | e0f1a5861f28 |
children | d9df76217991 |
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 | |
77 | |
5 | 78 function getHour($hour) |
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])) |
82 $stamp = mktime($hourStamps[$hour][0], $hourStamps[$hour][1], 0); | |
83 else | |
84 $stamp = mktime($hour + 8, 0, 0); | |
85 | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
86 return "<br />".date("H:i", $stamp)." - ".date("H:i", $stamp + 45 * 60)."<br /><br />"; |
5 | 87 } |
88 | |
89 | |
1 | 90 function matchCourse($id) |
91 { | |
92 global $cache, $infoURI, $cacheDirty; | |
93 | |
94 // Check if course exists in cache | |
95 if (!isset($cache[$id])) { | |
96 $cacheDirty = TRUE; | |
97 // Not cached, try to fetch data | |
98 $data = @file_get_contents($infoURI.$id); | |
99 if ($data !== FALSE) { | |
100 if (preg_match("#<td class=\"smallheadercell\"><strong>(.+?)\s+(\d+)\s*op\s*</strong></td>#", $data, $m)) { | |
101 // Add data to cache | |
102 $cache[$id] = array("desc" => $m[1], "op" => intval($m[2])); | |
103 } | |
104 } | |
105 } | |
106 | |
107 if (isset($cache[$id])) | |
108 return "<a target=\"_blank\" title=\"".htmlentities($id." - ".$cache[$id]["op"]." op"). | |
109 "\" href=\"".htmlentities($infoURI.$id)."\">".htmlentities($cache[$id]["desc"])."</a>"; | |
110 else | |
111 return htmlentities($id); | |
112 } | |
113 | |
114 | |
115 function matchClass($matches) | |
116 { | |
117 global $baseURI; | |
5 | 118 return "<b><a href=\"".$baseURI."?tila=".$matches[1]."\">".$matches[1]."</a></b> ".$matches[2]; |
1 | 119 } |
120 | |
121 | |
122 // Global cache for course data | |
123 $cache = array(); | |
124 $cacheDirty = FALSE; | |
125 | |
126 | |
127 // Try to read cachefile, if we can get file lock on it | |
128 $fp = @fopen($cacheFile, "rb"); | |
129 if ($fp) { | |
130 if (flock($fp, LOCK_SH)) { | |
131 require($cacheFile); | |
132 flock($fp, LOCK_UN); | |
133 } | |
134 fclose($fp); | |
135 } | |
136 | |
5 | 137 $fp = @fopen($classFile, "rb"); |
138 $classes = array(); | |
139 if ($fp) { | |
140 if (flock($fp, LOCK_SH)) { | |
141 while (!feof($fp)) { | |
142 $str = trim(fgets($fp, 128)); | |
143 if ($str[0] != "#" && strlen($str) > 2) | |
144 $classes[] = $str; | |
145 } | |
146 flock($fp, LOCK_UN); | |
147 } | |
148 fclose($fp); | |
17 | 149 } else { |
150 errorMsg("Luokkien listaa ei löytynyt. Kokeile ladata sivu uudelleen hetken kuluttua."); | |
1 | 151 } |
152 | |
153 | |
5 | 154 if (!file_exists($dataDir.$luokka.".data")) { |
17 | 155 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 | 156 $haveData = FALSE; |
157 } else { | |
158 require($dataDir.$luokka.".data"); | |
159 $haveData = isset($classDefs); | |
1 | 160 } |
161 | |
5 | 162 |
163 function printHourInfo($dayHours, $showDays) | |
164 { | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
165 $out = " <tr>\n <td>Tunteja<br />(<b>ryhmä/vv</b>)</td>\n"; |
5 | 166 for ($day = 0; $day < $showDays; $day++) { |
167 $out .= " <td>".$dayHours[$day]["total"]."h (<b>".$dayHours[$day]["grouped"]."h</b>)</td>\n"; | |
168 } | |
169 return $out." </tr>\n"; | |
1 | 170 } |
171 | |
172 | |
12
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
173 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
|
174 { |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
175 global $classHourTable, $classInfo; |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
176 $n = 0; |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
177 for ($i = $start; $i < $classInfo["maxhours"]; $i++) |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
178 if ($classHourTable[$i][$day] == $cmp) { |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
179 if ($mark) $classHourTable[$i][$day] = -9999; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
180 $n++; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
181 } else |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
182 break; |
12
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
183 return $n; |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
184 } |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
185 |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
186 |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
187 function findNextHour(&$j, &$i, $day, $hour, $chk) |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
188 { |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
189 global $classInfo, $classHourTable; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
190 for ($j = $day; $j < $classInfo["maxdays"]; $j++) |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
191 for ($i = $hour; $i < $classInfo["maxhours"]; $i++) { |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
192 // echo "chk=$chk - i=$i / j=$j : ht=".$classHourTable[$i][$j]."<br />\n"; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
193 if (($chk > 0 && $classHourTable[$i][$j] != $chk) || $classHourTable[$i][$j] > 0) |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
194 return $classHourTable[$i][$j]; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
195 } |
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 return -1; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
198 } |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
199 |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
200 |
19 | 201 function getHourInfo($isSplit, $d) |
202 { | |
203 if ($isSplit) { | |
204 $out = "<table>". | |
205 "<tr><td>".matchCourse($d[0])."</td><td>".matchCourse($d[1])."</td></tr>"; | |
206 | |
207 for ($j = 2; $j < count($d); $j += 2) | |
208 $out .= "<tr><td>".htmlentities($d[$j])."</td><td>".(isset($d[$j+1]) ? htmlentities($d[$j+1]) : "")."</td></tr>"; | |
209 | |
210 return $out."</table>"; | |
211 } else { | |
212 $out = matchCourse($d[0])."<br />"; | |
213 | |
214 for ($j = 1; $j < count($d); $j++) | |
215 $out .= htmlentities($d[$j])."<br />"; | |
216 | |
217 return $out; | |
218 } | |
219 } | |
220 | |
221 | |
222 function getHourInfoData($id) | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
223 { |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
224 global $classDefs; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
225 |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
226 if (isset($id)) { |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
227 if ($id >= 0 && isset($classDefs[$id])) { |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
228 $i = $classDefs[$id]; |
19 | 229 $isSplit = preg_match("/^[A-Z]\d{6}$/", $i["data"][1]); |
230 return getHourInfo($isSplit, $i["data"]); | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
231 } else |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
232 return "<p>Ei tunteja.</p>"; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
233 } else |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
234 return "<p>Ei mitään.</p>"; |
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 return ""; |
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 |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
239 |
17 | 240 if ($miniMode) { |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
241 $aika = getdate(); |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
242 $hour = $aika["hours"] - 8; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
243 $day = $aika["wday"] - 1; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
244 if ($day < 0) $day = 7; |
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 $chk = $classHourTable[$hour][$day]; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
247 |
18 | 248 $out = "<div class=\"content\">\n". |
249 "<h2>".$dayNames[$day]." ".$aika["mday"].".".$aika["mon"].".".$aika["year"]." - klo ".$aika["hours"].":".$aika["minutes"]."</h2>\n". | |
19 | 250 getHourInfoData($chk)."\n"; |
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 // $out .= "hour=".$hour."/day=".$day."<br />\n"; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
253 if ($day >= $classInfo["maxdays"]) { |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
254 $day = $hour = 0; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
255 $chk = -1; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
256 } else |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
257 if ($hour < 0) { |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
258 $hour = 0; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
259 $chk = -1; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
260 } else |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
261 if ($hour >= $classInfo["maxhours"]) { |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
262 $day++; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
263 $hour = 0; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
264 $chk = -1; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
265 } |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
266 // $out .= "hour=".$hour."/day=".$day."<br />\n"; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
267 |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
268 $found = findNextHour($nday, $nhour, $day, $hour, $chk); |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
269 |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
270 // $out .= "hour=".$nhour."/day=".$nday."/found=".$found."<br />\n"; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
271 |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
272 if ($found > 0) { |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
273 $stamp = mktime(8 + $nhour, 15, 0, $aika["mon"], $aika["mday"] + $nday - $day, $aika["year"]); |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
274 $aika = getdate($stamp); |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
275 $hour = $aika["hours"] - 8; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
276 $day = $aika["wday"] - 1; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
277 if ($day < 0) $day = 7; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
278 $out .= "<h2>Seuraavaksi: ".$dayNames[$nday]." ".date("d.n.Y", $stamp)." - klo ".date("H:i", $stamp)."</h2>\n". |
19 | 279 getHourInfoData($found)."\n". |
18 | 280 "</div>\n"; |
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 } |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
283 else |
5 | 284 if ($haveData) { |
285 $totalHours = 0; | |
286 $totalGrouped = 0; | |
287 $dayHours = array(); | |
7 | 288 |
11 | 289 for ($day = 0; $day < $classInfo["maxdays"]; $day++) { |
5 | 290 $dayHours[$day]["total"] = $dayHours[$day]["grouped"] = 0; |
1 | 291 |
11 | 292 for ($hour = 0; $hour < $classInfo["maxhours"]; $hour++) { |
293 $id = $classHourTable[$hour][$day]; | |
1 | 294 |
11 | 295 if ($id > 0) { |
296 $totalHours++; | |
297 $dayHours[$day]["total"]++; | |
298 | |
299 if ($classDefs[$id]["grouped"]) { | |
300 $totalGrouped++; | |
301 $dayHours[$day]["grouped"]++; | |
302 } | |
303 } | |
5 | 304 } |
305 } | |
306 | |
307 // Create the timetable table | |
308 $out = | |
309 "<p>".join("; ", $classInfo["general"])."</p>\n". | |
11 | 310 "<div>Viikossa yhteensä <b>".$totalHours."</b> tuntia, joista <b>".$totalGrouped."</b> ryhmissä tai vuoroviikoin.</div>\n". |
5 | 311 "<table class=\"timetable\">". |
312 " <tr>\n <th></th>\n"; | |
7 | 313 for ($day = 0; $day < $classInfo["maxdays"]; $day++) { |
18 | 314 $out .= " <th style=\"width: ".(100 / $classInfo["maxdays"]). |
315 "%;\" class=\"days\">".$dayNames[$day]."</th>\n"; | |
5 | 316 } |
317 $out .= " </tr>\n"; | |
1 | 318 |
319 for ($hour = 0; $hour < $classInfo["maxhours"]; $hour++) { | |
5 | 320 $out .= " <tr>\n". |
321 " <th class=\"hours\">".getHour($hour)."</th>\n"; | |
7 | 322 for ($day = 0; $day < $classInfo["maxdays"]; $day++) { |
1 | 323 if (isset($classHourTable[$hour][$day])) { |
324 $h = $classHourTable[$hour][$day]; | |
325 | |
326 if ($h < 1) { | |
10
6272ca0cacea
Make editing of custom timetable easier.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
327 if ($h > -9999) { |
12
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
328 $n = findHours($hour, $day, $h, TRUE); |
5 | 329 $out .= " <td rowspan=\"".$n."\" class=\"clnothing\"></td>\n"; |
1 | 330 } |
331 } else | |
332 if (isset($classDefs[$h])) { | |
333 if (!isset($classDefs[$h]["done"])) { | |
334 $classDefs[$h]["done"] = true; | |
335 $i = $classDefs[$h]; | |
336 $d = $classDefs[$h]["data"]; | |
337 | |
338 $isSplit = preg_match("/^[A-Z]\d{6}$/", $d[1]); | |
339 | |
12
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
340 $hours = findHours($hour, $day, $h, FALSE); |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
341 if ($hours != $i["hours"]) { |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
342 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
|
343 } |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
344 |
306028aa2253
Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
345 $out .= " <td rowspan=\"".$hours. |
19 | 346 "\" class=\"".($isSplit || $i["grouped"] ? "clgrouped" : "clnormal")."\">". |
347 getHourInfo($isSplit, $d). | |
348 "<div class=\"nhours\"><span>".$hours."h</span></div></td>\n"; | |
1 | 349 } |
350 } else | |
351 errorMsg("Internal error cell $hour / $day : hour id $h does not exist!"); | |
352 } else | |
353 errorMsg("Internal error, cell $hour / $day does not exist."); | |
354 } | |
5 | 355 $out .= " </tr>\n"; |
1 | 356 } |
357 | |
7 | 358 $out .= printHourInfo($dayHours, $classInfo["maxdays"]). |
14 | 359 "</table>\n"; |
5 | 360 |
361 } // haveData | |
362 | |
363 | |
364 $pageTitle = $haveData ? $luokka." / ".join("; ", $classInfo["info"]) : $luokka; | |
365 printPageHeader($pageTitle); | |
18 | 366 |
367 if ($miniMode) echo "<div id=\"mini\">\n"; | |
5 | 368 |
18 | 369 echo |
370 "<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
|
371 " <table>\n". |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
372 " <tr>\n". |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
373 " <td>\n". |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
374 " <select name=\"luokka\">\n"; |
5 | 375 |
376 foreach ($classes as $class) { | |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
377 echo " <option ".($luokka == $class ? "selected=\"selected\" " : "")."value=\"".$class."\">".htmlentities($class)."</option>\n"; |
1 | 378 } |
13
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
379 echo |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
380 " </select>\n". |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
381 " </td>\n". |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
382 " <td><input type=\"submit\" value=\" Vaihda \" /></td>\n". |
17 | 383 " <td>[<a href=\"".$baseURI."?luokka=".$luokka; |
384 | |
385 if ($miniMode) | |
386 echo "\">Normaali"; | |
387 else | |
388 echo "&nyt\">Mini-info"; | |
389 | |
390 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
|
391 " <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
|
392 " </tr>\n". |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
393 " </table>\n". |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
394 "</form>\n"; |
57dd1db922c2
Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
395 |
18 | 396 echo "<h1>".$pageTitle."</h1>\n"; |
1 | 397 |
398 // Show error messages | |
399 if ($errorSet) { | |
400 echo "<ul>\n"; | |
401 foreach ($errorMsgs as $msg) | |
402 echo "<li>$msg</li>\n"; | |
403 echo "</ul>\n"; | |
404 } | |
405 | |
5 | 406 echo $out; |
407 | |
17 | 408 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 | 409 |
410 if ($miniMode) echo "</div>\n"; | |
1 | 411 printPageFooter(); |
412 | |
413 | |
414 // Dump the course data cache, but only if it has changed | |
415 if ($cacheDirty) { | |
416 // First try append mode | |
417 $fp = @fopen($cacheFile, "rb+"); | |
418 | |
419 // If file didn't exist, try write mode | |
420 if (!$fp) | |
421 $fp = @fopen($cacheFile, "wb"); | |
422 | |
423 if ($fp) { | |
424 // Use locking to prevent concurrent access and dump data | |
425 if (flock($fp, LOCK_EX)) { | |
426 ftruncate($fp, 0); | |
427 fwrite($fp, "<?\n\$cache = array(\n"); | |
428 foreach ($cache as $id => $data) { | |
429 fwrite($fp, " \"".addslashes($id)."\" => array(\"desc\" => \"". | |
430 addslashes($data["desc"])."\", \"op\" => ".$data["op"]."),\n"); | |
431 } | |
432 fwrite($fp, ");\n?>"); | |
433 } | |
434 fclose($fp); | |
435 } | |
436 } | |
437 | |
438 ?> |