Exemplo n.º 1
0
function _make_html_table($table, $item, $urlPrefix, $n, &$data)
{
    $dbh = getdbh();
    //pagination
    $stmt = $dbh->query("SELECT count(OID) total FROM {$table}");
    $total = $stmt->fetchColumn();
    $limit = $GLOBALS['pagination']['per_page'];
    $data['body'][] = '<p>Showing records ' . ($n + 1) . ' to ' . min($total, $n + $limit) . ' of ' . $total . '</p>';
    $data['body'][] = pagination::makePagination($n, $total, myUrl("{$urlPrefix}/manage"), $GLOBALS['pagination']);
    //table
    $fields = "stationId,_1st,_2nd,_3rd,_4th,_5th,tolerance";
    $stmt = $dbh->query("SELECT OID,CID,{$fields} FROM {$table} LIMIT {$n},{$limit}");
    if ($stmt === false) {
        var_dump($dbh->errorInfo());
        return;
    }
    $tablearr[] = explode(',', $fields);
    while ($rs = $stmt->fetch(PDO::FETCH_ASSOC)) {
        $OID = $rs['OID'];
        $CID = $rs['CID'];
        $row = null;
        foreach ($tablearr[0] as $f) {
            if ($f == "stationId") {
                $tmp = new Station($rs[$f], -1);
                // todo fix this hack need view?
                $row[] = htmlspecialchars($tmp->get('tag'));
            } else {
                $row[] = htmlspecialchars($rs[$f]);
            }
        }
        $row[] = '<a href="' . myUrl("{$urlPrefix}/edit/{$OID}/{$CID}") . '">Edit</a> | ' . '<a href="javascript:jsconfirm(\'Really Delete ' . $item . '?\',\'' . myUrl("{$urlPrefix}/ops_delete/{$OID}/{$CID}") . '\')">Delete</a>';
        $tablearr[] = $row;
    }
    $data['body'][] = table::makeTable($tablearr);
    $data['head'][] = '<script type="text/javascript" src="' . myUrl('js/jsconfirm.js') . '"></script>';
}