<?php
// Returns HTML to begin a table.
function beginTable($tableAttr = "") {
    $html = "<table";
    if ($tableAttr) $html .= " $tableAttr";
    $html .= ">\n";
    return $html;
}

// Returns HTML to end a table.
function endTable() {
    return "</table>\n";
}

// Returns a row of table data from an array of data.
// If item is_array() then assume list($item, $attr)
// Adding attribute 'th' will cause use of th tag
function makeRow($rowList, $cellAttr = "") {
    $html = "<tr";
    $html .= ">\n";
    foreach ($rowList as $item) {
        $attr = $cellAttr;
        if (is_array($item)) {
            list($item, $attr) = $item;
        }
        $tag = "td";
        if ("th" === strtolower(trim($attr))) {
            $tag = "th";
            $attr = $cellAttr;
        }
        $html .= "  <$tag";
        if ($attr) $html .= " $attr";
        if ($item) {
            $html .= ">$item</$tag>\n";
        } else {
            $html .= ">&nbsp;</$tag>\n";
        }
    }
    $html .= "</tr>\n";
    return $html;
}

// Returns many rows where $set is an array of arrays
function makeSet($set) {
    $html = "";
    foreach($set as $field) {
        $html .= makeRow($field);
    }
    return $html;
}
?>