Mercurial > hg > lukkari
diff 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 |
line wrap: on
line diff
--- a/index.php Wed Jan 12 02:54:52 2011 +0200 +++ b/index.php Wed Jan 12 03:06:46 2011 +0200 @@ -198,30 +198,36 @@ } -function getHourInfo($id) +function getHourInfo($isSplit, $d) +{ + if ($isSplit) { + $out = "<table>". + "<tr><td>".matchCourse($d[0])."</td><td>".matchCourse($d[1])."</td></tr>"; + + for ($j = 2; $j < count($d); $j += 2) + $out .= "<tr><td>".htmlentities($d[$j])."</td><td>".(isset($d[$j+1]) ? htmlentities($d[$j+1]) : "")."</td></tr>"; + + return $out."</table>"; + } else { + $out = matchCourse($d[0])."<br />"; + + for ($j = 1; $j < count($d); $j++) + $out .= htmlentities($d[$j])."<br />"; + + return $out; + } +} + + +function getHourInfoData($id) { global $classDefs; if (isset($id)) { if ($id >= 0 && isset($classDefs[$id])) { $i = $classDefs[$id]; - $d = $i["data"]; - $out = ""; - - $isSplit = preg_match("/^[A-Z]\d{6}$/", $d[1]); - if ($isSplit) { - $out .= "<table>". - "<tr><td>".matchCourse($d[0])."</td><td>".matchCourse($d[1])."</td></tr>"; - for ($j = 2; $j < count($d); $j += 2) - $out .= "<tr><td>".htmlentities($d[$j])."</td><td>".(isset($d[$j+1]) ? htmlentities($d[$j+1]) : "")."</td></tr>"; - $out .= "</table>"; - } else { - $out .= matchCourse($d[0])."<br />"; - for ($j = 1; $j < count($d); $j++) - $out .= htmlentities($d[$j])."<br />"; - } - - return $out; + $isSplit = preg_match("/^[A-Z]\d{6}$/", $i["data"][1]); + return getHourInfo($isSplit, $i["data"]); } else return "<p>Ei tunteja.</p>"; } else @@ -241,7 +247,7 @@ $out = "<div class=\"content\">\n". "<h2>".$dayNames[$day]." ".$aika["mday"].".".$aika["mon"].".".$aika["year"]." - klo ".$aika["hours"].":".$aika["minutes"]."</h2>\n". - getHourInfo($chk)."\n"; + getHourInfoData($chk)."\n"; // $out .= "hour=".$hour."/day=".$day."<br />\n"; if ($day >= $classInfo["maxdays"]) { @@ -270,7 +276,7 @@ $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". - getHourInfo($found)."\n". + getHourInfoData($found)."\n". "</div>\n"; } } @@ -337,20 +343,9 @@ } $out .= " <td rowspan=\"".$hours. - "\" class=\"".($isSplit || $i["grouped"] ? "clgrouped" : "clnormal")."\">"; - - if ($isSplit) { - $out .= "<table>". - "<tr><td>".matchCourse($d[0])."</td><td>".matchCourse($d[1])."</td></tr>"; - for ($j = 2; $j < count($d); $j += 2) - $out .= "<tr><td>".htmlentities($d[$j])."</td><td>".(isset($d[$j+1]) ? htmlentities($d[$j+1]) : "")."</td></tr>"; - $out .= "</table>"; - } else { - $out .= matchCourse($d[0])."<br />"; - for ($j = 1; $j < count($d); $j++) - $out .= htmlentities($d[$j])."<br />"; - } - $out .= "<div class=\"nhours\"><span>".$hours."h</span></div></td>\n"; + "\" class=\"".($isSplit || $i["grouped"] ? "clgrouped" : "clnormal")."\">". + getHourInfo($isSplit, $d). + "<div class=\"nhours\"><span>".$hours."h</span></div></td>\n"; } } else errorMsg("Internal error cell $hour / $day : hour id $h does not exist!");