comparison beta.php @ 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
comparison
equal deleted inserted replaced
11:03c393c347c7 12:306028aa2253
142 } 142 }
143 return $out." </tr>\n"; 143 return $out." </tr>\n";
144 } 144 }
145 145
146 146
147 function findHours($start, $day, $cmp, $mark = FALSE)
148 {
149 global $classHourTable, $classInfo;
150 $n = 0;
151 for ($i = $start; $i < $classInfo["maxhours"]; $i++)
152 if ($classHourTable[$i][$day] == $cmp) {
153 if ($mark) $classHourTable[$i][$day] = -9999;
154 $n++;
155 } else
156 break;
157 return $n;
158 }
159
160
147 if ($haveData) { 161 if ($haveData) {
148 $totalHours = 0; 162 $totalHours = 0;
149 $totalGrouped = 0; 163 $totalGrouped = 0;
150 $dayHours = array(); 164 $dayHours = array();
151 165
185 if (isset($classHourTable[$hour][$day])) { 199 if (isset($classHourTable[$hour][$day])) {
186 $h = $classHourTable[$hour][$day]; 200 $h = $classHourTable[$hour][$day];
187 201
188 if ($h < 1) { 202 if ($h < 1) {
189 if ($h > -9999) { 203 if ($h > -9999) {
190 $n = 0; 204 $n = findHours($hour, $day, $h, TRUE);
191 for ($i = $hour; $i < $classInfo["maxhours"]; $i++)
192 if ($classHourTable[$i][$day] == $h) {
193 $classHourTable[$i][$day] = -9999;
194 $n++;
195 } else
196 break;
197 $out .= " <td rowspan=\"".$n."\" class=\"clnothing\"></td>\n"; 205 $out .= " <td rowspan=\"".$n."\" class=\"clnothing\"></td>\n";
198 } 206 }
199 } else 207 } else
200 if (isset($classDefs[$h])) { 208 if (isset($classDefs[$h])) {
201 if (!isset($classDefs[$h]["done"])) { 209 if (!isset($classDefs[$h]["done"])) {
203 $i = $classDefs[$h]; 211 $i = $classDefs[$h];
204 $d = $classDefs[$h]["data"]; 212 $d = $classDefs[$h]["data"];
205 213
206 $isSplit = preg_match("/^[A-Z]\d{6}$/", $d[1]); 214 $isSplit = preg_match("/^[A-Z]\d{6}$/", $d[1]);
207 215
208 $out .= " <td rowspan=\"".$i["hours"]. 216 $hours = findHours($hour, $day, $h, FALSE);
217 if ($hours != $i["hours"]) {
218 errorMsg("Internal error, cell $hour / $day : hour id $h hours ($hours) do not match ".$i["hours"]."!");
219 }
220
221 $out .= " <td rowspan=\"".$hours.
209 "\" class=\"".($isSplit || $i["grouped"] ? "clgrouped" : "clnormal")."\">"; 222 "\" class=\"".($isSplit || $i["grouped"] ? "clgrouped" : "clnormal")."\">";
210 223
211 if ($isSplit) { 224 if ($isSplit) {
212 $out .= "<table>". 225 $out .= "<table>".
213 "<tr><td>".matchCourse($d[0])."</td><td>".matchCourse($d[1])."</td></tr>"; 226 "<tr><td>".matchCourse($d[0])."</td><td>".matchCourse($d[1])."</td></tr>";
217 } else { 230 } else {
218 $out .= matchCourse($d[0])."<br />"; 231 $out .= matchCourse($d[0])."<br />";
219 for ($j = 1; $j < count($d); $j++) 232 for ($j = 1; $j < count($d); $j++)
220 $out .= htmlentities($d[$j])."<br />"; 233 $out .= htmlentities($d[$j])."<br />";
221 } 234 }
222 $out .= "<div class=\"nhours\"><span>".$i["hours"]."h</span></div></td>\n"; 235 $out .= "<div class=\"nhours\"><span>".$hours."h</span></div></td>\n";
223 } 236 }
224 } else 237 } else
225 errorMsg("Internal error cell $hour / $day : hour id $h does not exist!"); 238 errorMsg("Internal error cell $hour / $day : hour id $h does not exist!");
226 } else 239 } else
227 errorMsg("Internal error, cell $hour / $day does not exist."); 240 errorMsg("Internal error, cell $hour / $day does not exist.");