# HG changeset patch # User Matti Hamalainen # Date 1346043367 -10800 # Node ID 7621bfc47491dd5f4958d9cc960b8aa866a9bb49 # Parent 76900cdfc066b14a63185c60beedfef9473c30d1 Various bits and pieces -- a commit that defies logic. Oh well. diff -r 76900cdfc066 -r 7621bfc47491 index.php --- a/index.php Mon Aug 27 07:55:22 2012 +0300 +++ b/index.php Mon Aug 27 07:56:07 2012 +0300 @@ -1,4 +1,7 @@ XXXnXXX, käytetään vakioarvoa ".$luokkaDefault."."); + lukErrorMsg("Virhe! Luokan täytyy olla muotoa XXXnXXX, käytetään vakioarvoa ".$luokkaDefault."."); $id = $luokkaDefault; return FALSE; } } -function getHourStamp($hour, $sec = 0, $mon = 0, $day = 0, $year = 0) +function lukMakeHourStamp($hour, $sec = 0, $mon = 0, $day = 0, $year = 0) { global $hourStamps; if (isset($hourStamps[$hour])) @@ -66,12 +69,12 @@ function getHour($hour) { - $stamp = getHourStamp($hour); + $stamp = lukMakeHourStamp($hour); return "
".date("H:i", $stamp)." - ".date("H:i", $stamp + 45 * 60)."

"; } -function matchCourse($id) +function lukMatchCourse($id) { global $cache, $infoURI, $cacheDirty, $internalCharset; @@ -90,14 +93,14 @@ } if (isset($cache[$id])) - return "".chentities($cache[$id]["desc"]).""; + return "".lukChEntities($cache[$id]["desc"]).""; else - return chentities($id); + return lukChEntities($id); } -function matchClass($matches) +function lukMatchClass($matches) { global $baseURI; return "".$matches[1]." ".$matches[2]; @@ -110,15 +113,15 @@ // Check given parameters if (isset($_GET["luokka"])) { $luokka = $_GET["luokka"]; - if (checkClassID($luokka) && !$miniMode) { + if (lukCheckClassID($luokka) && !$miniMode) { setcookie("lukluokka", $luokka, time() + 365*24*60*60); // expire in a year } } else if (isset($_COOKIE["lukluokka"])) { $luokka = $_COOKIE["lukluokka"]; - checkClassID($luokka); + lukCheckClassID($luokka); } else { - errorMsg("Luokkaa ei asetettu, käytetään vakioarvoa ".$luokkaDefault."."); + lukErrorMsg("Luokkaa ei asetettu, käytetään vakioarvoa ".$luokkaDefault."."); $luokka = $luokkaDefault; } @@ -158,6 +161,7 @@ fclose($fp); } + // Read classfile $fp = @fopen($classFile, "rb"); $classes = array(); @@ -165,19 +169,19 @@ if (flock($fp, LOCK_SH)) { while (!feof($fp)) { $str = trim(fgets($fp, 128)); - if ($str[0] != "#" && strlen($str) > 2) + if (strlen($str) > 2 && $str[0] != "#") $classes[] = $str; } flock($fp, LOCK_UN); } fclose($fp); } else { - errorMsg("Luokkien listaa ei löytynyt. Kokeile ladata sivu uudelleen hetken kuluttua."); + lukErrorMsg("Luokkien listaa ei löytynyt. Kokeile ladata sivu uudelleen hetken kuluttua."); } if (!file_exists($dataFile)) { - errorMsg("Luokan ".chentities($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."); + lukErrorMsg("Luokan ".lukChEntities($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."); $haveData = FALSE; } else { require($dataFile); @@ -195,7 +199,7 @@ } -function findHours($start, $day, $cmp, $mark = FALSE) +function lukResolveHours($start, $day, $cmp, $mark = FALSE) { global $classHourTable, $classInfo; $n = 0; @@ -230,17 +234,17 @@ { if ($isSplit) { $out = "". - ""; + ""; for ($j = 2; $j < count($d); $j += 2) - $out .= ""; + $out .= ""; return $out."
".matchCourse($d[0])."".matchCourse($d[1])."
".lukMatchCourse($d[0])."".lukMatchCourse($d[1])."
".chentities($d[$j])."".(isset($d[$j+1]) ? chentities($d[$j+1]) : "")."
".lukChEntities($d[$j])."".(isset($d[$j+1]) ? lukChEntities($d[$j+1]) : "")."
"; } else { - $out = matchCourse($d[0])."
"; + $out = lukMatchCourse($d[0])."
"; for ($j = 1; $j < count($d); $j++) - $out .= chentities($d[$j])."
"; + $out .= lukChEntities($d[$j])."
"; return $out; } @@ -265,23 +269,27 @@ } -if ($miniMode) { +if ($miniMode && $haveData) { $stamp = time(); $aika = getdate($stamp); $day = $aika["wday"] - 1; if ($day < 0) $day = 7; $hour = $aika["hours"] - 8; - $id = $classHourTable[$hour][$day]; - - $out = "
\n". - "

".$dayNames[$day]." ".date("d.n.Y", $stamp)." - klo ".date("H:i", $stamp)."

\n". - getHourInfoData($id)."\n"; + $out = "
\n"; + + if ($hour >= 0 && $day >= 0) + { + $id = $classHourTable[$hour][$day]; + $out .= + "

".$dayNames[$day]." ".date("d.n.Y", $stamp)." - klo ".date("H:i", $stamp)."

\n". + getHourInfoData($id)."\n"; + } if (isset($id) && $id >= 0 && isset($classDefs[$id])) { $i = $classDefs[$id]; - $start = getHourStamp($i["start"]); + $start = lukMakeHourStamp($i["start"]); } // echo "day=$day, hour=$hour, id=$id
\n"; @@ -307,7 +315,7 @@ $out .= "

Seuraavaksi"; if ($found > 0) { - $stamp = getHourStamp($nhour, 0, 0, $aika["mon"], $aika["mday"] + $nday - $day, $aika["year"]); + $stamp = lukMakeHourStamp($nhour, 0, 0, $aika["mon"], $aika["mday"] + $nday - $day, $aika["year"]); $aika = getdate($stamp); $out .= ": ".$dayNames[$nday]." ".date("d.n.Y", $stamp)." - klo ".date("H:i", $stamp)."

\n". getHourInfoData($found)."\n"; @@ -363,7 +371,7 @@ if ($h < 1) { if ($h > -9999) { - $n = findHours($hour, $day, $h, TRUE); + $n = lukResolveHours($hour, $day, $h, TRUE); $out .= " \n"; } } else @@ -375,9 +383,9 @@ $isSplit = preg_match("/^[A-Z]\d{6}$/", $d[1]); - $hours = findHours($hour, $day, $h, FALSE); + $hours = lukResolveHours($hour, $day, $h, FALSE); if ($hours != $i["hours"]) { - errorMsg("Internal error, cell $hour / $day : hour id $h hours ($hours) do not match ".$i["hours"]."!"); + lukErrorMsg("Internal error, cell $hour / $day : hour id $h hours ($hours) do not match ".$i["hours"]."!"); } $out .= " ".$hours."h
\n"; } } else - errorMsg("Internal error cell $hour / $day : hour id $h does not exist!"); + lukErrorMsg("Internal error cell $hour / $day : hour id $h does not exist!"); } else - errorMsg("Internal error, cell $hour / $day does not exist."); + lukErrorMsg("Internal error, cell $hour / $day does not exist."); } $out .= " \n"; } @@ -413,7 +421,7 @@ "; foreach ($classes as $class) { - echo " \n"; + echo " \n"; } echo " @@ -440,7 +448,7 @@ // Show error messages if ($errorSet) { echo "\n"; }