Mercurial > hg > lukkari
changeset 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 |
files | beta.php |
diffstat | 1 files changed, 129 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/beta.php Tue Jan 11 23:05:49 2011 +0200 +++ b/beta.php Wed Jan 12 01:01:02 2011 +0200 @@ -11,6 +11,22 @@ $infoURI = "http://www.oamk.fi/opiskelijalle/rakenne/opinto-opas/koulutusohjelmat/?sivu=oj&kieli=FI&opas=2010-2011&vuosi=10S11K&koodi1="; $dayNames = array("Maanantai", "Tiistai", "Keskiviikko", "Torstai", "Perjantai", "Lauantai", "Sunnuntai"); +$hourStamps = array( + array( 8, 15), + array( 9, 15), + array(10, 15), + array(11, 15), + array(12, 15), + array(13, 15), + array(14, 15), + array(15, 15), + array(16, 15), + array(17, 5), + array(18, 5), + array(19, 0), + array(20, 45), +); + // Include framework require "mcommon.inc.php"; require "merrors.inc.php"; @@ -32,7 +48,7 @@ // Check given parameters if (isset($_GET["luokka"])) { $luokka = $_GET["luokka"]; - if (checkClassID($luokka)) { + if (checkClassID($luokka) && !isset($_["nyt"])) { setcookie("lukluokka", $luokka, time() + 365*24*60*60); // expire in a year } } else @@ -59,7 +75,9 @@ function getHour($hour) { - return "<br />".($hour + 8).":15 - ".($hour + 9).":00<br /><br />"; + global $hourStamps; + $stamp = mktime($hourStamps[$hour][0], $hourStamps[$hour][1], 0); + return "<br />".date("H:i", $stamp)." - ".date("H:i", $stamp + 45 * 60)."<br /><br />"; } @@ -136,7 +154,7 @@ function printHourInfo($dayHours, $showDays) { - $out = " <tr>\n <td>Tunteja (<b>ryhmä</b>)</td>\n"; + $out = " <tr>\n <td>Tunteja<br />(<b>ryhmä/vv</b>)</td>\n"; for ($day = 0; $day < $showDays; $day++) { $out .= " <td>".$dayHours[$day]["total"]."h (<b>".$dayHours[$day]["grouped"]."h</b>)</td>\n"; } @@ -149,15 +167,104 @@ global $classHourTable, $classInfo; $n = 0; for ($i = $start; $i < $classInfo["maxhours"]; $i++) - if ($classHourTable[$i][$day] == $cmp) { - if ($mark) $classHourTable[$i][$day] = -9999; - $n++; - } else - break; + if ($classHourTable[$i][$day] == $cmp) { + if ($mark) $classHourTable[$i][$day] = -9999; + $n++; + } else + break; return $n; } +function findNextHour(&$j, &$i, $day, $hour, $chk) +{ + global $classInfo, $classHourTable; + for ($j = $day; $j < $classInfo["maxdays"]; $j++) + for ($i = $hour; $i < $classInfo["maxhours"]; $i++) { +// echo "chk=$chk - i=$i / j=$j : ht=".$classHourTable[$i][$j]."<br />\n"; + if (($chk > 0 && $classHourTable[$i][$j] != $chk) || $classHourTable[$i][$j] > 0) + return $classHourTable[$i][$j]; + } + + return -1; +} + + +function getHourInfo($id) +{ + global $classDefs; + + if (isset($id)) { + if ($id >= 0 && isset($classDefs[$id])) { + $i = $classDefs[$id]; + $d = $i["data"]; + $out = ""; + + $isSplit = preg_match("/^[A-Z]\d{6}$/", $d[1]); + if ($isSplit) { + $out .= "<table>". + "<tr><td>".matchCourse($d[0])."</td><td>".matchCourse($d[1])."</td></tr>"; + for ($j = 2; $j < count($d); $j += 2) + $out .= "<tr><td>".htmlentities($d[$j])."</td><td>".(isset($d[$j+1]) ? htmlentities($d[$j+1]) : "")."</td></tr>"; + $out .= "</table>"; + } else { + $out .= matchCourse($d[0])."<br />"; + for ($j = 1; $j < count($d); $j++) + $out .= htmlentities($d[$j])."<br />"; + } + + return $out; + } else + return "<p>Ei tunteja.</p>"; + } else + return "<p>Ei mitään.</p>"; + + return ""; +} + + +if (isset($_GET["nyt"])) { + $aika = getdate(); + $hour = $aika["hours"] - 8; + $day = $aika["wday"] - 1; + if ($day < 0) $day = 7; + + $chk = $classHourTable[$hour][$day]; + + $out = "<h2>".$dayNames[$day]." ".$aika["mday"].".".$aika["mon"].".".$aika["year"]." - klo ".$aika["hours"].":".$aika["minutes"]."</h2>\n". + getHourInfo($chk)."\n"; + +// $out .= "hour=".$hour."/day=".$day."<br />\n"; + if ($day >= $classInfo["maxdays"]) { + $day = $hour = 0; + $chk = -1; + } else + if ($hour < 0) { + $hour = 0; + $chk = -1; + } else + if ($hour >= $classInfo["maxhours"]) { + $day++; + $hour = 0; + $chk = -1; + } +// $out .= "hour=".$hour."/day=".$day."<br />\n"; + + $found = findNextHour($nday, $nhour, $day, $hour, $chk); + +// $out .= "hour=".$nhour."/day=".$nday."/found=".$found."<br />\n"; + + if ($found > 0) { + $stamp = mktime(8 + $nhour, 15, 0, $aika["mon"], $aika["mday"] + $nday - $day, $aika["year"]); + $aika = getdate($stamp); + $hour = $aika["hours"] - 8; + $day = $aika["wday"] - 1; + if ($day < 0) $day = 7; + $out .= "<h2>Seuraavaksi: ".$dayNames[$nday]." ".date("d.n.Y", $stamp)." - klo ".date("H:i", $stamp)."</h2>\n". + getHourInfo($found)."\n"; + } +} +else if ($haveData) { $totalHours = 0; $totalGrouped = 0; @@ -253,12 +360,23 @@ echo "<h1>".$pageTitle."</h1>\n"; echo "<form action=\"".$baseURI."\" method=\"get\">\n". -" <select name=\"luokka\">\n"; +" <table>\n". +" <tr>\n". +" <td>\n". +" <select name=\"luokka\">\n"; foreach ($classes as $class) { - echo " <option value=\"".$class."\">".htmlentities($class)."</option>\n"; + echo " <option ".($luokka == $class ? "selected=\"selected\" " : "")."value=\"".$class."\">".htmlentities($class)."</option>\n"; } -echo " </select>\n <input type=\"submit\" value=\" Vaihda \" />\n</form>\n"; +echo +" </select>\n". +" </td>\n". +" <td><input type=\"submit\" value=\" Vaihda \" /></td>\n". +" <td>[<a href=\"".$baseURI."?luokka=".$luokka."&nyt\">Mini-info moodi</a>]</td>\n". +" </tr>\n". +" </table>\n". +"</form>\n"; + // Show error messages if ($errorSet) {