Beispiel #1
0
function dbtable_html_list($tablear, $tablename, $href, $fields, $keys, $order)
{
    global $CELLBG, $THBG, $THFG;
    if (!is_array($tablear)) {
        return 'Error: dbtable_to_html_list parameter 1 is not an array!<br />' . "\n";
    }
    if (!is_array($fields)) {
        return 'Error: dbtable_to_html_list parameter 2 is not an array!<br />' . "\n";
    }
    if (!is_array($keys)) {
        return 'Error: dbtable_to_html_list parameter 3 is not an array!<br />' . "\n";
    }
    $ret = '
    <table>
      <tr>
        <td style="background-color:#000000;">
          <table style="border:0; width:100%;" cellspacing="1" cellpadding="2">
            <tr>
              <td style="width:100%; background-color:' . $CELLBG . ';">
                <table style="border:0; width:100%;">
                  <tr>';
    // header
    $fieldcnt = count($fields);
    for ($i = 0; $i < $fieldcnt; $i++) {
        $ind = dbtable_get_field_index($tablear, $fields[$i]);
        /*
            if ( $ind < 0 )
         echo 'Error: dbtable_html_list invalid fieldname "' . $fields[$i] . "\" $i\n";
         exit;
        */
        if (empty($tablear[$ind]['hide'])) {
            $ret .= '
                    <th style="background-color:' . $THBG . '; color:' . $THFG . ';">' . $tablear[$ind]['prompt'] . '</th>';
        }
    }
    $ret .= '
                  </tr>';
    $query_params = array();
    $sql = 'SELECT ' . $fields[0];
    for ($i = 1; $i < $fieldcnt; $i++) {
        $sql .= ', ' . $fields[$i];
    }
    $sql .= ' FROM ' . $tablename . ' ';
    if (is_array($keys) && count($keys) > 0) {
        $sql .= 'WHERE ';
        $first = 1;
        for ($i = 0, $cnt = count($tablear); $i < $cnt; $i++) {
            if (!empty($tablear[$i]['iskey'])) {
                if (empty($keys[$tablear[$i]['name']])) {
                    // echo 'Error: key value for ' . $tablear[$i]['name'] . ' not set.' . "\n";
                    // exit;
                } else {
                    if ($first) {
                        $first = 0;
                    } else {
                        $sql .= ' AND ';
                    }
                    $query_params[] = $keys[$tablear[$i]['name']];
                    $sql .= $tablear[$i]['name'] . ' = ?';
                }
            }
        }
    }
    if (!empty($order)) {
        $sql .= ' ORDER BY ' . $order;
    }
    $res = dbi_execute($sql, $query_params);
    if ($res) {
        while ($row = dbi_fetch_row($res)) {
            $ret .= '
                  <tr>';
            $first_href = 1;
            $first = 1;
            for ($i = 0; $i < $fieldcnt; $i++) {
                // Check data type (date).
                $ind = dbtable_get_field_index($tablear, $fields[$i]);
                if (empty($tablear[$ind]['hide'])) {
                    $ret .= '
                    <td style="background-color:' . $CELLBG . '; vertical-align:top;">';
                    if ($tablear[$ind]['type'] == 'date') {
                        $val = date_to_str($row[$i], '', 1, 1);
                    } elseif ($tablear[$ind]['type'] == 'dbdate') {
                        $val = date_to_str(sprintf("%04d%02d%02d", substr($row[$i], 0, 4), substr($row[$i], 5, 2), substr($row[$i], 8, 2)), '', 1, 1);
                    } else {
                        $val = htmlentities($row[$i]);
                    }
                    if ($first_href && !empty($href)) {
                        $first_href = 0;
                        $url = $href;
                        for ($j = count($fields) - 1; $j >= 0; $j--) {
                            $url = str_replace("%{$j}", $row[$j], $url);
                        }
                        $ret .= '<a href="' . $url . '">' . $val . '</a>';
                    } else {
                        $ret .= $val;
                    }
                    $ret .= '</td>';
                }
            }
            $ret .= '
                  </tr>';
        }
    } else {
        dbi_error(true);
    }
    return $ret . '
                </table>
              </td>
            </tr>
          </table>
        </td>
      </tr>
    </table>';
}
Beispiel #2
0
function dbtable_html_list($tablear, $tablename, $href, $fields, $keys, $order)
{
    global $THBG, $THFG, $CELLBG;
    if (!is_array($tablear)) {
        return "Error: dbtable_to_html_list parameter 1 is not an array!\n<br />\n";
    }
    if (!is_array($fields)) {
        return "Error: dbtable_to_html_list parameter 2 is not an array!\n<br />\n";
    }
    if (!is_array($keys)) {
        return "Error: dbtable_to_html_list parameter 3 is not an array!\n<br />\n";
    }
    $ret = "<table style=\"border-width:0px;\" cellspacing=\"0\" cellpadding=\"0\">" . "<tr><td style=\"background-color:#000000;\">" . "<table style=\"border-width:0px; width:100%;\" cellspacing=\"1\" cellpadding=\"2\">" . "<tr><td style=\"width:100%; background-color:{$CELLBG};\">" . "<table style=\"border-width:0px; width:100%;\">\n";
    // header
    $ret .= "<tr>";
    for ($i = 0; $i < count($fields); $i++) {
        $ind = dbtable_get_field_index($tablear, $fields[$i]);
        /*
            if ( $ind < 0 )
              echo "Error: dbtable_html_list invalid fieldname \"$fields[$i]\" $i\n"; exit;
        */
        if (empty($tablear[$ind]["hide"])) {
            $ret .= "<th style=\"background-color:{$THBG}; color:{$THFG};\">" . $tablear[$ind]["prompt"] . "</th>";
        }
    }
    $ret .= "</tr>\n";
    $sql = "SELECT " . $fields[0];
    for ($i = 1; $i < count($fields); $i++) {
        $sql .= ", " . $fields[$i];
    }
    $sql .= " FROM " . $tablename . " ";
    if (is_array($keys) && count($keys) > 0) {
        $sql .= "WHERE ";
        $first = 1;
        for ($i = 0; $i < count($tablear); $i++) {
            if (!empty($tablear[$i]["iskey"])) {
                if (empty($keys[$tablear[$i]["name"]])) {
                    //echo "Error: key value for " . $tablear[$i]["name"] . " not set.\n";
                    //exit;
                } else {
                    if ($first) {
                        $first = 0;
                    } else {
                        $sql .= " AND ";
                    }
                    $sql .= $tablear[$i]["name"] . " = ";
                    if ($tablear[$i]["type"] == "int" || $tablear[$i]["type"] == "float" || $tablear[$i]["type"] == "date") {
                        $sql .= $keys[$tablear[$i]["name"]];
                    } else {
                        $sql .= "'" . $keys[$tablear[$i]["name"]] . "'";
                    }
                }
            }
        }
    }
    if (!empty($order)) {
        $sql .= " ORDER BY " . $order;
    }
    //echo "SQL: $sql<br />\n";
    $res = dbi_query($sql);
    if ($res) {
        while ($row = dbi_fetch_row($res)) {
            $ret .= "<tr>";
            $first_href = 1;
            $first = 1;
            for ($i = 0; $i < count($fields); $i++) {
                // check data type (date)
                $ind = dbtable_get_field_index($tablear, $fields[$i]);
                if (empty($tablear[$ind]["hide"])) {
                    $ret .= "<td style=\"background-color:{$CELLBG}; vertical-align:top;\">";
                    if ($tablear[$ind]["type"] == "date") {
                        $val = date_to_str($row[$i], "", 1, 1);
                    } else {
                        if ($tablear[$ind]["type"] == "dbdate") {
                            $y = substr($row[$i], 0, 4);
                            $m = substr($row[$i], 5, 2);
                            $d = substr($row[$i], 8, 2);
                            $date = sprintf("%04d%02d%02d", $y, $m, $d);
                            $val = date_to_str($date, "", 1, 1);
                        } else {
                            $val = htmlentities($row[$i]);
                        }
                    }
                    if ($first_href && !empty($href)) {
                        $first_href = 0;
                        $url = $href;
                        for ($j = count($fields) - 1; $j >= 0; $j--) {
                            $url = str_replace("%{$j}", $row[$j], $url);
                        }
                        $ret .= "<a href=\"{$url}\">" . $val . "</a>";
                    } else {
                        $ret .= $val;
                    }
                    $ret .= "</td>";
                }
            }
            $ret .= "</tr>\n";
        }
    } else {
        echo translate("Database error") . ": " . dbi_error();
        exit;
    }
    $ret .= "</table>\n</td></tr></table>\n</td></tr></table>\n";
    return $ret;
}
function dbtable_html_list($tablear, $tablename, $href, $fields, $keys, $order)
{
    global $THBG, $THFG, $CELLBG;
    if (!is_array($tablear)) {
        return "Error: dbtable_to_html_list parameter 1 is not an array!\n<BR>\n";
    }
    if (!is_array($fields)) {
        return "Error: dbtable_to_html_list parameter 2 is not an array!\n<BR>\n";
    }
    if (!is_array($keys)) {
        return "Error: dbtable_to_html_list parameter 3 is not an array!\n<BR>\n";
    }
    $ret = "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\">" . "<TR><TD BGCOLOR=\"#000000\">" . "<TABLE BORDER=\"0\" WIDTH=\"100%\" CELLSPACING=\"1\" CELLPADDING=\"2\">" . "<TR><TD WIDTH=\"100%\" BGCOLOR=\"{$CELLBG}\">" . "<TABLE BORDER=\"0\" WIDTH=\"100%\">\n";
    // header
    $ret .= "<TR>";
    for ($i = 0; $i < count($fields); $i++) {
        $ind = dbtable_get_field_index($tablear, $fields[$i]);
        /*
            if ( $ind < 0 )
              echo "Error: dbtable_html_list invalid fieldname \"$fields[$i]\" $i\n"; exit;
        */
        if (empty($tablear[$ind]["hide"])) {
            $ret .= "<TH BGCOLOR=\"{$THBG}\">" . "<FONT COLOR=\"{$THFG}\">" . $tablear[$ind]["prompt"] . "</FONT></TH>";
        }
    }
    $ret .= "</TR>\n";
    $sql = "SELECT " . $fields[0];
    for ($i = 1; $i < count($fields); $i++) {
        $sql .= ", " . $fields[$i];
    }
    $sql .= " FROM " . $tablename . " ";
    if (is_array($keys) && count($keys) > 0) {
        $sql .= "WHERE ";
        $first = 1;
        for ($i = 0; $i < count($tablear); $i++) {
            if (!empty($tablear[$i]["iskey"])) {
                if (empty($keys[$tablear[$i]["name"]])) {
                    //echo "Error: key value for " . $tablear[$i]["name"] . " not set.\n";
                    //exit;
                } else {
                    if ($first) {
                        $first = 0;
                    } else {
                        $sql .= " AND ";
                    }
                    $sql .= $tablear[$i]["name"] . " = ";
                    if ($tablear[$i]["type"] == "int" || $tablear[$i]["type"] == "float" || $tablear[$i]["type"] == "date") {
                        $sql .= $keys[$tablear[$i]["name"]];
                    } else {
                        $sql .= "'" . $keys[$tablear[$i]["name"]] . "'";
                    }
                }
            }
        }
    }
    if (!empty($order)) {
        $sql .= " ORDER BY " . $order;
    }
    //echo "SQL: $sql<P>\n";
    $res = dbi_query($sql);
    if ($res) {
        while ($row = dbi_fetch_row($res)) {
            $ret .= "<TR>";
            $first_href = 1;
            $first = 1;
            for ($i = 0; $i < count($fields); $i++) {
                // check data type (date)
                $ind = dbtable_get_field_index($tablear, $fields[$i]);
                if (empty($tablear[$ind]["hide"])) {
                    $ret .= "<TD BGCOLOR=\"{$CELLBG}\" VALIGN=\"top\">";
                    if ($tablear[$ind]["type"] == "date") {
                        $val = date_to_str($row[$i], "", 1, 1);
                    } else {
                        if ($tablear[$ind]["type"] == "dbdate") {
                            $y = substr($row[$i], 0, 4);
                            $m = substr($row[$i], 5, 2);
                            $d = substr($row[$i], 8, 2);
                            $date = sprintf("%04d%02d%02d", $y, $m, $d);
                            $val = date_to_str($date, "", 1, 1);
                        } else {
                            $val = htmlentities($row[$i]);
                        }
                    }
                    if ($first_href && !empty($href)) {
                        $first_href = 0;
                        $url = $href;
                        for ($j = count($fields) - 1; $j >= 0; $j--) {
                            $url = str_replace("%{$j}", $row[$j], $url);
                        }
                        $ret .= "<A HREF=\"{$url}\">" . $val . "</A>";
                    } else {
                        $ret .= $val;
                    }
                    $ret .= "</TD>";
                }
            }
            $ret .= "</TR>\n";
        }
    } else {
        echo translate("Database error") . ": " . dbi_error();
        exit;
    }
    $ret .= "</TABLE>\n</TD></TR></TABLE>\n</TD></TR></TABLE>\n";
    return $ret;
}