# HG changeset patch # User Matti Hamalainen # Date 1294775915 -7200 # Node ID 3d6a83eaa2bad36e5e32a21ec9e78b91a3557dcf # Parent dd2bce7ec0c8b0621a783d22f97e286dd647556a Improvements. diff -r dd2bce7ec0c8 -r 3d6a83eaa2ba beta.php --- a/beta.php Tue Jan 11 20:55:09 2011 +0200 +++ b/beta.php Tue Jan 11 21:58:35 2011 +0200 @@ -2,26 +2,23 @@ $pageCSS = array("http://tnsp.org/docs1.css", "luk.css"); $pageCharset = "iso-8859-15"; $luokkaDefault = "TTE9SNO"; +$dataDir = "cache/"; +$classFile = "luokat.txt"; $mapFile = "kartta.png"; -$classFile = "luokkatilat.txt"; +$roomFile = "luokkatilat.txt"; $cacheFile = "coursecache.txt"; -$baseURI = "http://tnsp.org/luk/?"; +$baseURI = "http://tnsp.org/luk/beta.php"; $infoURI = "http://www.oamk.fi/opiskelijalle/rakenne/opinto-opas/koulutusohjelmat/?sivu=oj&kieli=FI&opas=2010-2011&vuosi=10S11K&koodi1="; $showDays = 6; $dayNames = array("Maanantai", "Tiistai", "Keskiviikko", "Torstai", "Perjantai", "Lauantai", "Sunnuntai"); - +// Include framework require "mcommon.inc.php"; require "merrors.inc.php"; -function getHour($hour) -{ - return "
".($hour + 8).":15 - ".($hour + 9).":00

"; -} - - +// Helper functions function checkClassID(&$id) { global $luokkaDefault; @@ -55,13 +52,19 @@ echo "Luokkatilan näyttömoodi ei vielä tuettu.
\n"; exit; - $fp = @fopen($classFile, "rb"); + $fp = @fopen($roomFile, "rb"); if ($fp) { fclose($fp); } } +function getHour($hour) +{ + return "
".($hour + 8).":15 - ".($hour + 9).":00

"; +} + + function matchCourse($id) { global $cache, $infoURI, $cacheDirty; @@ -90,7 +93,7 @@ function matchClass($matches) { global $baseURI; - return "".$matches[1]." ".$matches[2]; + return "".$matches[1]." ".$matches[2]; } @@ -109,55 +112,80 @@ fclose($fp); } - -if (file_exists($luokka.".data")) { - require($luokka.".data"); -} else { - errorMsg("Luokan ".htmlentities($luokka)." datatiedostoa ei löytynyt!"); +$fp = @fopen($classFile, "rb"); +$classes = array(); +if ($fp) { + if (flock($fp, LOCK_SH)) { + while (!feof($fp)) { + $str = trim(fgets($fp, 128)); + if ($str[0] != "#" && strlen($str) > 2) + $classes[] = $str; + } + flock($fp, LOCK_UN); + } + fclose($fp); } -$totalHours = 0; -$totalGrouped = 0; -$dayHours = array(); -for ($day = 0; $day < $showDays; $day++) - $dayHours[$day]["total"] = $dayHours[$day]["grouped"] = 0; -foreach ($classDefs as $id => $data) { - $h = $data["hours"]; - - $totalHours += $h; - $dayHours[$data["day"]]["total"] += $h; - - if (!$data["grouped"]) { - $totalGrouped += $h; - $dayHours[$data["day"]]["grouped"] += $h; - } +if (!file_exists($dataDir.$luokka.".data")) { + errorMsg("Luokan ".htmlentities($luokka)." datatiedostoa ei löytynyt!"); + $haveData = FALSE; +} else { + require($dataDir.$luokka.".data"); + $haveData = isset($classDefs); } -for ($day = $showDays - 1; $day >= 0; $day--) { - if ($dayHours[$day]["total"] == 0) - $showDays--; - else - break; + +function printHourInfo($dayHours, $showDays) +{ + $out = " \n Tunteja (ryhmä)\n"; + for ($day = 0; $day < $showDays; $day++) { + $out .= " ".$dayHours[$day]["total"]."h (".$dayHours[$day]["grouped"]."h)\n"; + } + return $out." \n"; } +if ($haveData) { + $totalHours = 0; + $totalGrouped = 0; + $dayHours = array(); + for ($day = 0; $day < $showDays; $day++) + $dayHours[$day]["total"] = $dayHours[$day]["grouped"] = 0; -$pageTitle = $luokka." / ".join("; ", $classInfo["info"]); -printPageHeader($pageTitle); -echo "

".$pageTitle."

\n". -"

".join("; ", $classInfo["general"])."

\n"; + foreach ($classDefs as $id => $data) { + $h = $data["hours"]; + + $totalHours += $h; + $dayHours[$data["day"]]["total"] += $h; -echo "". -" \n \n"; -for ($day = 0; $day < $showDays; $day++) { - echo " \n"; -} -echo " \n"; + if (!$data["grouped"]) { + $totalGrouped += $h; + $dayHours[$data["day"]]["grouped"] += $h; + } + } + + for ($day = $showDays - 1; $day >= 0; $day--) { + if ($dayHours[$day]["total"] == 0) + $showDays--; + else + break; + } + + + // Create the timetable table + $out = + "

".join("; ", $classInfo["general"])."

\n". + "
".$dayNames[$day]."
". + " \n \n"; + for ($day = 0; $day < $showDays; $day++) { + $out .= " \n"; + } + $out .= " \n"; for ($hour = 0; $hour < $classInfo["maxhours"]; $hour++) { - echo " \n"; - echo " \n"; + $out .= " \n". + " \n"; for ($day = 0; $day < $showDays; $day++) { if (isset($classHourTable[$hour][$day])) { $h = $classHourTable[$hour][$day]; @@ -171,7 +199,7 @@ $n++; } else break; - echo " \n"; + $out .= " \n"; } } else if (isset($classDefs[$h])) { @@ -182,38 +210,47 @@ $isSplit = preg_match("/^[A-Z]\d{6}$/", $d[1]); - echo " "; + $out .= "
".$dayNames[$day]."
".getHour($hour)."
".getHour($hour).""; if ($isSplit) { - echo "". + $out .= "
". ""; for ($j = 2; $j < count($d); $j += 2) - echo ""; - echo "
".matchCourse($d[0])."".matchCourse($d[1])."
".htmlentities($d[$j])."".(isset($d[$j+1]) ? htmlentities($d[$j+1]) : "")."
"; + $out .= "
".htmlentities($d[$j])."".(isset($d[$j+1]) ? htmlentities($d[$j+1]) : "")."
"; } else { - echo matchCourse($d[0])."
"; + $out .= matchCourse($d[0])."
"; for ($j = 1; $j < count($d); $j++) - echo htmlentities($d[$j])."
"; + $out .= htmlentities($d[$j])."
"; } - echo "\n"; + $out .= "
".$i["hours"]."h
\n"; } } else errorMsg("Internal error cell $hour / $day : hour id $h does not exist!"); } else errorMsg("Internal error, cell $hour / $day does not exist."); } - echo " \n"; + $out .= " \n"; } -echo " \n Tunteja (ryhmä)\n"; -for ($day = 0; $day < $showDays; $day++) { - echo " ".$dayHours[$day]["total"]."h (".$dayHours[$day]["grouped"]."h)\n"; + $out .= printHourInfo($dayHours, $showDays). + ""; + +} // haveData + + +$pageTitle = $haveData ? $luokka." / ".join("; ", $classInfo["info"]) : $luokka; +printPageHeader($pageTitle); +echo "

".$pageTitle."

\n"; + +echo "
\n". +" \n \n
\n"; // Show error messages if ($errorSet) { @@ -223,6 +260,8 @@ echo "\n"; } +echo $out; + printPageFooter(); diff -r dd2bce7ec0c8 -r 3d6a83eaa2ba luk.css --- a/luk.css Tue Jan 11 20:55:09 2011 +0200 +++ b/luk.css Tue Jan 11 21:58:35 2011 +0200 @@ -32,3 +32,13 @@ td.clnormal { } + +div.nhours { + text-align: right; +} + +div.nhours span { + background: black; + padding: 2pt; + border: 1px solid gray; +}