changeset 12:306028aa2253

Fix hour counts when table has been modified.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 11 Jan 2011 23:05:49 +0200
parents 03c393c347c7
children 57dd1db922c2
files beta.php
diffstat 1 files changed, 22 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/beta.php	Tue Jan 11 22:46:37 2011 +0200
+++ b/beta.php	Tue Jan 11 23:05:49 2011 +0200
@@ -144,6 +144,20 @@
 }
 
 
+function findHours($start, $day, $cmp, $mark = FALSE)
+{
+  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;
+  return $n;
+}
+
+
 if ($haveData) {
   $totalHours = 0;
   $totalGrouped = 0;
@@ -187,13 +201,7 @@
         
       if ($h < 1) {
         if ($h > -9999) {
-          $n = 0;
-          for ($i = $hour; $i < $classInfo["maxhours"]; $i++)
-          if ($classHourTable[$i][$day] == $h) {
-            $classHourTable[$i][$day] = -9999;
-            $n++;
-          } else
-            break;
+          $n = findHours($hour, $day, $h, TRUE);
           $out .= "  <td rowspan=\"".$n."\" class=\"clnothing\"></td>\n";
         }
       } else
@@ -205,7 +213,12 @@
           
           $isSplit = preg_match("/^[A-Z]\d{6}$/", $d[1]);
           
-          $out .= "  <td rowspan=\"".$i["hours"].
+          $hours = findHours($hour, $day, $h, FALSE);
+          if ($hours != $i["hours"]) {
+            errorMsg("Internal error, cell $hour / $day : hour id $h hours ($hours) do not match ".$i["hours"]."!");
+          }
+          
+          $out .= "  <td rowspan=\"".$hours.
           "\" class=\"".($isSplit || $i["grouped"] ? "clgrouped" : "clnormal")."\">";
           
           if ($isSplit) {
@@ -219,7 +232,7 @@
             for ($j = 1; $j < count($d); $j++)
               $out .= htmlentities($d[$j])."<br />";
           }
-          $out .= "<div class=\"nhours\"><span>".$i["hours"]."h</span></div></td>\n";
+          $out .= "<div class=\"nhours\"><span>".$hours."h</span></div></td>\n";
         }
       } else
         errorMsg("Internal error cell $hour / $day : hour id $h does not exist!");