changeset 20:d9df76217991

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 12 Jan 2011 03:59:36 +0200
parents 777791321149
children d0c8dda49726
files index.php
diffstat 1 files changed, 44 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/index.php	Wed Jan 12 03:06:46 2011 +0200
+++ b/index.php	Wed Jan 12 03:59:36 2011 +0200
@@ -74,15 +74,20 @@
   }
 }
 
-  
-function getHour($hour)
+
+function getHourStamp($hour, $sec = 0, $mon = 0, $day = 0, $year = 0)
 {
   global $hourStamps;
   if (isset($hourStamps[$hour]))
-    $stamp = mktime($hourStamps[$hour][0], $hourStamps[$hour][1], 0);
+    return mktime($hourStamps[$hour][0], $hourStamps[$hour][1], $sec, $mon, $year);
   else
-    $stamp = mktime($hour + 8, 0, 0);
+    return mktime($hour + 8, 0, $sec, $mon, $year);
+}
+  
 
+function getHour($hour)
+{
+  $stamp = getHourStamp($hour);
   return "<br />".date("H:i", $stamp)." - ".date("H:i", $stamp + 45 * 60)."<br /><br />";
 }
 
@@ -187,10 +192,13 @@
 function findNextHour(&$j, &$i, $day, $hour, $chk)
 {
   global $classInfo, $classHourTable;
-  for ($j = $day; $j < $classInfo["maxdays"]; $j++)
+//  for ($j = $day; $j < $classInfo["maxdays"]; $j++)
+    $j = $day;
     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)
+      if ($chk > 0 && $classHourTable[$i][$j] != $chk)
+        return $classHourTable[$i][$j];
+
+      if ($classHourTable[$i][$j] > 0 && $classHourTable[$i][$j] != $chk)
         return $classHourTable[$i][$j];
     }
 
@@ -238,47 +246,57 @@
 
 
 if ($miniMode) {
-  $aika = getdate();
-  $hour = $aika["hours"] - 8;
+  $stamp = time();
+  $aika = getdate($stamp);
   $day = $aika["wday"] - 1;
   if ($day < 0) $day = 7;
+  $hour = $aika["hours"] - 8;
 
-  $chk = $classHourTable[$hour][$day];
+  $id = $classHourTable[$hour][$day];
 
   $out = "<div class=\"content\">\n".
-  "<h2>".$dayNames[$day]." ".$aika["mday"].".".$aika["mon"].".".$aika["year"]." - klo ".$aika["hours"].":".$aika["minutes"]."</h2>\n".
-  getHourInfoData($chk)."\n";
+  "<h2>".$dayNames[$day]." ".date("d.n.Y", $stamp)." - klo ".date("H:i", $stamp)."</h2>\n".
+  getHourInfoData($id)."\n";
   
-//  $out .= "hour=".$hour."/day=".$day."<br />\n";
+
+  if (isset($id) && $id >= 0 && isset($classDefs[$id])) {
+    $i = $classDefs[$id];
+    $start = getHourStamp($i["start"]);
+  }
+
+//  echo "day=$day, hour=$hour, id=$id<br />\n";
+  
   if ($day >= $classInfo["maxdays"]) {
     $day = $hour = 0;
-    $chk = -1;
+    $id = -1;
   } else
   if ($hour < 0) {
     $hour = 0;
-    $chk = -1;
+    $id = -1;
   } else
   if ($hour >= $classInfo["maxhours"]) {
     $day++;
     $hour = 0;
-    $chk = -1;
+    $id = -1;
   }
-//  $out .= "hour=".$hour."/day=".$day."<br />\n";
 
-  $found = findNextHour($nday, $nhour, $day, $hour, $chk);
+//  echo "day=$day, hour=$hour, id=$id<br />\n";
+  $found = findNextHour($nday, $nhour, $day, $hour, $id);
 
-//  $out .= "hour=".$nhour."/day=".$nday."/found=".$found."<br />\n";
+//  echo "nday=$nday, nhour=$nhour, id=$found<br />\n";
 
+  $out .= "<h2>Seuraavaksi";
   if ($found > 0) {
-    $stamp = mktime(8 + $nhour, 15, 0, $aika["mon"], $aika["mday"] + $nday - $day, $aika["year"]);
+    $stamp = getHourStamp($nhour, 0, 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".
-    getHourInfoData($found)."\n".
-    "</div>\n";
+    $out .= ": ".$dayNames[$nday]." ".date("d.n.Y", $stamp)." - klo ".date("H:i", $stamp)."</h2>\n".
+    getHourInfoData($found)."\n";
+  } else {
+    $out .= "</h2>\n".
+    "<p>Ei mitään</p>\n";
   }
+
+  $out .= "</div>\n";
 }
 else
 if ($haveData) {