Mercurial > hg > lukkari
comparison beta.php @ 13:57dd1db922c2
Fix hours, add mini-info mode.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 12 Jan 2011 01:01:02 +0200 |
parents | 306028aa2253 |
children | a2c61b010680 |
comparison
equal
deleted
inserted
replaced
12:306028aa2253 | 13:57dd1db922c2 |
---|---|
9 $cacheFile = "coursecache.txt"; | 9 $cacheFile = "coursecache.txt"; |
10 $baseURI = "http://tnsp.org/luk/beta.php"; | 10 $baseURI = "http://tnsp.org/luk/beta.php"; |
11 $infoURI = "http://www.oamk.fi/opiskelijalle/rakenne/opinto-opas/koulutusohjelmat/?sivu=oj&kieli=FI&opas=2010-2011&vuosi=10S11K&koodi1="; | 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"); | 12 $dayNames = array("Maanantai", "Tiistai", "Keskiviikko", "Torstai", "Perjantai", "Lauantai", "Sunnuntai"); |
13 | 13 |
14 $hourStamps = array( | |
15 array( 8, 15), | |
16 array( 9, 15), | |
17 array(10, 15), | |
18 array(11, 15), | |
19 array(12, 15), | |
20 array(13, 15), | |
21 array(14, 15), | |
22 array(15, 15), | |
23 array(16, 15), | |
24 array(17, 5), | |
25 array(18, 5), | |
26 array(19, 0), | |
27 array(20, 45), | |
28 ); | |
29 | |
14 // Include framework | 30 // Include framework |
15 require "mcommon.inc.php"; | 31 require "mcommon.inc.php"; |
16 require "merrors.inc.php"; | 32 require "merrors.inc.php"; |
17 | 33 |
18 | 34 |
30 | 46 |
31 | 47 |
32 // Check given parameters | 48 // Check given parameters |
33 if (isset($_GET["luokka"])) { | 49 if (isset($_GET["luokka"])) { |
34 $luokka = $_GET["luokka"]; | 50 $luokka = $_GET["luokka"]; |
35 if (checkClassID($luokka)) { | 51 if (checkClassID($luokka) && !isset($_["nyt"])) { |
36 setcookie("lukluokka", $luokka, time() + 365*24*60*60); // expire in a year | 52 setcookie("lukluokka", $luokka, time() + 365*24*60*60); // expire in a year |
37 } | 53 } |
38 } else | 54 } else |
39 if (isset($_COOKIE["lukluokka"])) { | 55 if (isset($_COOKIE["lukluokka"])) { |
40 $luokka = $_COOKIE["lukluokka"]; | 56 $luokka = $_COOKIE["lukluokka"]; |
57 } | 73 } |
58 | 74 |
59 | 75 |
60 function getHour($hour) | 76 function getHour($hour) |
61 { | 77 { |
62 return "<br />".($hour + 8).":15 - ".($hour + 9).":00<br /><br />"; | 78 global $hourStamps; |
79 $stamp = mktime($hourStamps[$hour][0], $hourStamps[$hour][1], 0); | |
80 return "<br />".date("H:i", $stamp)." - ".date("H:i", $stamp + 45 * 60)."<br /><br />"; | |
63 } | 81 } |
64 | 82 |
65 | 83 |
66 function matchCourse($id) | 84 function matchCourse($id) |
67 { | 85 { |
134 } | 152 } |
135 | 153 |
136 | 154 |
137 function printHourInfo($dayHours, $showDays) | 155 function printHourInfo($dayHours, $showDays) |
138 { | 156 { |
139 $out = " <tr>\n <td>Tunteja (<b>ryhmä</b>)</td>\n"; | 157 $out = " <tr>\n <td>Tunteja<br />(<b>ryhmä/vv</b>)</td>\n"; |
140 for ($day = 0; $day < $showDays; $day++) { | 158 for ($day = 0; $day < $showDays; $day++) { |
141 $out .= " <td>".$dayHours[$day]["total"]."h (<b>".$dayHours[$day]["grouped"]."h</b>)</td>\n"; | 159 $out .= " <td>".$dayHours[$day]["total"]."h (<b>".$dayHours[$day]["grouped"]."h</b>)</td>\n"; |
142 } | 160 } |
143 return $out." </tr>\n"; | 161 return $out." </tr>\n"; |
144 } | 162 } |
147 function findHours($start, $day, $cmp, $mark = FALSE) | 165 function findHours($start, $day, $cmp, $mark = FALSE) |
148 { | 166 { |
149 global $classHourTable, $classInfo; | 167 global $classHourTable, $classInfo; |
150 $n = 0; | 168 $n = 0; |
151 for ($i = $start; $i < $classInfo["maxhours"]; $i++) | 169 for ($i = $start; $i < $classInfo["maxhours"]; $i++) |
152 if ($classHourTable[$i][$day] == $cmp) { | 170 if ($classHourTable[$i][$day] == $cmp) { |
153 if ($mark) $classHourTable[$i][$day] = -9999; | 171 if ($mark) $classHourTable[$i][$day] = -9999; |
154 $n++; | 172 $n++; |
173 } else | |
174 break; | |
175 return $n; | |
176 } | |
177 | |
178 | |
179 function findNextHour(&$j, &$i, $day, $hour, $chk) | |
180 { | |
181 global $classInfo, $classHourTable; | |
182 for ($j = $day; $j < $classInfo["maxdays"]; $j++) | |
183 for ($i = $hour; $i < $classInfo["maxhours"]; $i++) { | |
184 // echo "chk=$chk - i=$i / j=$j : ht=".$classHourTable[$i][$j]."<br />\n"; | |
185 if (($chk > 0 && $classHourTable[$i][$j] != $chk) || $classHourTable[$i][$j] > 0) | |
186 return $classHourTable[$i][$j]; | |
187 } | |
188 | |
189 return -1; | |
190 } | |
191 | |
192 | |
193 function getHourInfo($id) | |
194 { | |
195 global $classDefs; | |
196 | |
197 if (isset($id)) { | |
198 if ($id >= 0 && isset($classDefs[$id])) { | |
199 $i = $classDefs[$id]; | |
200 $d = $i["data"]; | |
201 $out = ""; | |
202 | |
203 $isSplit = preg_match("/^[A-Z]\d{6}$/", $d[1]); | |
204 if ($isSplit) { | |
205 $out .= "<table>". | |
206 "<tr><td>".matchCourse($d[0])."</td><td>".matchCourse($d[1])."</td></tr>"; | |
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 $out .= "</table>"; | |
210 } else { | |
211 $out .= matchCourse($d[0])."<br />"; | |
212 for ($j = 1; $j < count($d); $j++) | |
213 $out .= htmlentities($d[$j])."<br />"; | |
214 } | |
215 | |
216 return $out; | |
155 } else | 217 } else |
156 break; | 218 return "<p>Ei tunteja.</p>"; |
157 return $n; | 219 } else |
158 } | 220 return "<p>Ei mitään.</p>"; |
159 | 221 |
160 | 222 return ""; |
223 } | |
224 | |
225 | |
226 if (isset($_GET["nyt"])) { | |
227 $aika = getdate(); | |
228 $hour = $aika["hours"] - 8; | |
229 $day = $aika["wday"] - 1; | |
230 if ($day < 0) $day = 7; | |
231 | |
232 $chk = $classHourTable[$hour][$day]; | |
233 | |
234 $out = "<h2>".$dayNames[$day]." ".$aika["mday"].".".$aika["mon"].".".$aika["year"]." - klo ".$aika["hours"].":".$aika["minutes"]."</h2>\n". | |
235 getHourInfo($chk)."\n"; | |
236 | |
237 // $out .= "hour=".$hour."/day=".$day."<br />\n"; | |
238 if ($day >= $classInfo["maxdays"]) { | |
239 $day = $hour = 0; | |
240 $chk = -1; | |
241 } else | |
242 if ($hour < 0) { | |
243 $hour = 0; | |
244 $chk = -1; | |
245 } else | |
246 if ($hour >= $classInfo["maxhours"]) { | |
247 $day++; | |
248 $hour = 0; | |
249 $chk = -1; | |
250 } | |
251 // $out .= "hour=".$hour."/day=".$day."<br />\n"; | |
252 | |
253 $found = findNextHour($nday, $nhour, $day, $hour, $chk); | |
254 | |
255 // $out .= "hour=".$nhour."/day=".$nday."/found=".$found."<br />\n"; | |
256 | |
257 if ($found > 0) { | |
258 $stamp = mktime(8 + $nhour, 15, 0, $aika["mon"], $aika["mday"] + $nday - $day, $aika["year"]); | |
259 $aika = getdate($stamp); | |
260 $hour = $aika["hours"] - 8; | |
261 $day = $aika["wday"] - 1; | |
262 if ($day < 0) $day = 7; | |
263 $out .= "<h2>Seuraavaksi: ".$dayNames[$nday]." ".date("d.n.Y", $stamp)." - klo ".date("H:i", $stamp)."</h2>\n". | |
264 getHourInfo($found)."\n"; | |
265 } | |
266 } | |
267 else | |
161 if ($haveData) { | 268 if ($haveData) { |
162 $totalHours = 0; | 269 $totalHours = 0; |
163 $totalGrouped = 0; | 270 $totalGrouped = 0; |
164 $dayHours = array(); | 271 $dayHours = array(); |
165 | 272 |
251 $pageTitle = $haveData ? $luokka." / ".join("; ", $classInfo["info"]) : $luokka; | 358 $pageTitle = $haveData ? $luokka." / ".join("; ", $classInfo["info"]) : $luokka; |
252 printPageHeader($pageTitle); | 359 printPageHeader($pageTitle); |
253 echo "<h1>".$pageTitle."</h1>\n"; | 360 echo "<h1>".$pageTitle."</h1>\n"; |
254 | 361 |
255 echo "<form action=\"".$baseURI."\" method=\"get\">\n". | 362 echo "<form action=\"".$baseURI."\" method=\"get\">\n". |
256 " <select name=\"luokka\">\n"; | 363 " <table>\n". |
364 " <tr>\n". | |
365 " <td>\n". | |
366 " <select name=\"luokka\">\n"; | |
257 | 367 |
258 foreach ($classes as $class) { | 368 foreach ($classes as $class) { |
259 echo " <option value=\"".$class."\">".htmlentities($class)."</option>\n"; | 369 echo " <option ".($luokka == $class ? "selected=\"selected\" " : "")."value=\"".$class."\">".htmlentities($class)."</option>\n"; |
260 } | 370 } |
261 echo " </select>\n <input type=\"submit\" value=\" Vaihda \" />\n</form>\n"; | 371 echo |
372 " </select>\n". | |
373 " </td>\n". | |
374 " <td><input type=\"submit\" value=\" Vaihda \" /></td>\n". | |
375 " <td>[<a href=\"".$baseURI."?luokka=".$luokka."&nyt\">Mini-info moodi</a>]</td>\n". | |
376 " </tr>\n". | |
377 " </table>\n". | |
378 "</form>\n"; | |
379 | |
262 | 380 |
263 // Show error messages | 381 // Show error messages |
264 if ($errorSet) { | 382 if ($errorSet) { |
265 echo "<ul>\n"; | 383 echo "<ul>\n"; |
266 foreach ($errorMsgs as $msg) | 384 foreach ($errorMsgs as $msg) |