comparison index.php @ 19:777791321149

Modularize, cleanup.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 12 Jan 2011 03:06:46 +0200
parents e0f1a5861f28
children d9df76217991
comparison
equal deleted inserted replaced
18:e0f1a5861f28 19:777791321149
196 196
197 return -1; 197 return -1;
198 } 198 }
199 199
200 200
201 function getHourInfo($id) 201 function getHourInfo($isSplit, $d)
202 {
203 if ($isSplit) {
204 $out = "<table>".
205 "<tr><td>".matchCourse($d[0])."</td><td>".matchCourse($d[1])."</td></tr>";
206
207 for ($j = 2; $j < count($d); $j += 2)
208 $out .= "<tr><td>".htmlentities($d[$j])."</td><td>".(isset($d[$j+1]) ? htmlentities($d[$j+1]) : "")."</td></tr>";
209
210 return $out."</table>";
211 } else {
212 $out = matchCourse($d[0])."<br />";
213
214 for ($j = 1; $j < count($d); $j++)
215 $out .= htmlentities($d[$j])."<br />";
216
217 return $out;
218 }
219 }
220
221
222 function getHourInfoData($id)
202 { 223 {
203 global $classDefs; 224 global $classDefs;
204 225
205 if (isset($id)) { 226 if (isset($id)) {
206 if ($id >= 0 && isset($classDefs[$id])) { 227 if ($id >= 0 && isset($classDefs[$id])) {
207 $i = $classDefs[$id]; 228 $i = $classDefs[$id];
208 $d = $i["data"]; 229 $isSplit = preg_match("/^[A-Z]\d{6}$/", $i["data"][1]);
209 $out = ""; 230 return getHourInfo($isSplit, $i["data"]);
210
211 $isSplit = preg_match("/^[A-Z]\d{6}$/", $d[1]);
212 if ($isSplit) {
213 $out .= "<table>".
214 "<tr><td>".matchCourse($d[0])."</td><td>".matchCourse($d[1])."</td></tr>";
215 for ($j = 2; $j < count($d); $j += 2)
216 $out .= "<tr><td>".htmlentities($d[$j])."</td><td>".(isset($d[$j+1]) ? htmlentities($d[$j+1]) : "")."</td></tr>";
217 $out .= "</table>";
218 } else {
219 $out .= matchCourse($d[0])."<br />";
220 for ($j = 1; $j < count($d); $j++)
221 $out .= htmlentities($d[$j])."<br />";
222 }
223
224 return $out;
225 } else 231 } else
226 return "<p>Ei tunteja.</p>"; 232 return "<p>Ei tunteja.</p>";
227 } else 233 } else
228 return "<p>Ei mitään.</p>"; 234 return "<p>Ei mitään.</p>";
229 235
239 245
240 $chk = $classHourTable[$hour][$day]; 246 $chk = $classHourTable[$hour][$day];
241 247
242 $out = "<div class=\"content\">\n". 248 $out = "<div class=\"content\">\n".
243 "<h2>".$dayNames[$day]." ".$aika["mday"].".".$aika["mon"].".".$aika["year"]." - klo ".$aika["hours"].":".$aika["minutes"]."</h2>\n". 249 "<h2>".$dayNames[$day]." ".$aika["mday"].".".$aika["mon"].".".$aika["year"]." - klo ".$aika["hours"].":".$aika["minutes"]."</h2>\n".
244 getHourInfo($chk)."\n"; 250 getHourInfoData($chk)."\n";
245 251
246 // $out .= "hour=".$hour."/day=".$day."<br />\n"; 252 // $out .= "hour=".$hour."/day=".$day."<br />\n";
247 if ($day >= $classInfo["maxdays"]) { 253 if ($day >= $classInfo["maxdays"]) {
248 $day = $hour = 0; 254 $day = $hour = 0;
249 $chk = -1; 255 $chk = -1;
268 $aika = getdate($stamp); 274 $aika = getdate($stamp);
269 $hour = $aika["hours"] - 8; 275 $hour = $aika["hours"] - 8;
270 $day = $aika["wday"] - 1; 276 $day = $aika["wday"] - 1;
271 if ($day < 0) $day = 7; 277 if ($day < 0) $day = 7;
272 $out .= "<h2>Seuraavaksi: ".$dayNames[$nday]." ".date("d.n.Y", $stamp)." - klo ".date("H:i", $stamp)."</h2>\n". 278 $out .= "<h2>Seuraavaksi: ".$dayNames[$nday]." ".date("d.n.Y", $stamp)." - klo ".date("H:i", $stamp)."</h2>\n".
273 getHourInfo($found)."\n". 279 getHourInfoData($found)."\n".
274 "</div>\n"; 280 "</div>\n";
275 } 281 }
276 } 282 }
277 else 283 else
278 if ($haveData) { 284 if ($haveData) {
335 if ($hours != $i["hours"]) { 341 if ($hours != $i["hours"]) {
336 errorMsg("Internal error, cell $hour / $day : hour id $h hours ($hours) do not match ".$i["hours"]."!"); 342 errorMsg("Internal error, cell $hour / $day : hour id $h hours ($hours) do not match ".$i["hours"]."!");
337 } 343 }
338 344
339 $out .= " <td rowspan=\"".$hours. 345 $out .= " <td rowspan=\"".$hours.
340 "\" class=\"".($isSplit || $i["grouped"] ? "clgrouped" : "clnormal")."\">"; 346 "\" class=\"".($isSplit || $i["grouped"] ? "clgrouped" : "clnormal")."\">".
341 347 getHourInfo($isSplit, $d).
342 if ($isSplit) { 348 "<div class=\"nhours\"><span>".$hours."h</span></div></td>\n";
343 $out .= "<table>".
344 "<tr><td>".matchCourse($d[0])."</td><td>".matchCourse($d[1])."</td></tr>";
345 for ($j = 2; $j < count($d); $j += 2)
346 $out .= "<tr><td>".htmlentities($d[$j])."</td><td>".(isset($d[$j+1]) ? htmlentities($d[$j+1]) : "")."</td></tr>";
347 $out .= "</table>";
348 } else {
349 $out .= matchCourse($d[0])."<br />";
350 for ($j = 1; $j < count($d); $j++)
351 $out .= htmlentities($d[$j])."<br />";
352 }
353 $out .= "<div class=\"nhours\"><span>".$hours."h</span></div></td>\n";
354 } 349 }
355 } else 350 } else
356 errorMsg("Internal error cell $hour / $day : hour id $h does not exist!"); 351 errorMsg("Internal error cell $hour / $day : hour id $h does not exist!");
357 } else 352 } else
358 errorMsg("Internal error, cell $hour / $day does not exist."); 353 errorMsg("Internal error, cell $hour / $day does not exist.");