Esempio n. 1
0
function BuildTable($db, $tbl, $pos = 1, $sortcol = '', $sortdesc = 0)
{
    $pospage = 8;
    //the display properties for the odd and even rows
    $odd = array('style' => 'background-color: #CCCCCC;');
    $even = array('style' => 'background-color: #EEEEEE;');
    //the display properties for the overall table
    $table = array('cellpadding' => '3', 'cellspacing' => '0');
    //table column header formatting properties
    $headerattrib = array('style' => 'background-color: skyblue; cursor:pointer;');
    //get data and rowcount
    $possql = $pos - 1;
    if ($sortcol) {
        $orderby = " ORDER BY {$sortcol} " . ($sortdesc ? 'DESC' : '');
    }
    $result = mysql_query("SELECT SQL_CALC_FOUND_ROWS * FROM {$tbl} {$orderby} LIMIT {$possql},{$pospage}");
    $poscnt = mysql_result(mysql_query("SELECT FOUND_ROWS()"), 0, 0);
    while ($row = mysql_fetch_assoc($result)) {
        $data[] = $row;
    }
    //build the datagrid
    require_once "./AjaxDataGrid.class.php";
    $at = new DataGrid($data, $_SERVER['PHP_SELF'] . "?db={$db}");
    $at->JsClass = $tbl;
    $at->pos = $pos;
    $at->pospage = $pospage;
    $at->poscnt = $poscnt;
    $at->SetEvenRowAttribs($even);
    $at->SetOddRowAttribs($odd);
    $at->SetTableAttribs($table);
    $at->SetHeaderAttribs($headerattrib);
    //NOTE: the columns types are setup automatically - first column readonly,
    //rest text. See example.php for setting up columns manually.
    return $at;
}
Esempio n. 2
0
function BuildTable($cls, $pos = 1, $sortcol = '', $sortdesc = 0)
{
    $pospage = 8;
    global $data_file;
    //the display properties for the odd and even rows
    $odd = array('style' => 'background-color: #CCCCCC;');
    $even = array('style' => 'background-color: #EEEEEE;');
    //the display properties for the overall table
    $table = array('cellpadding' => '3', 'cellspacing' => '0');
    //table column header formatting properties
    $headerattrib = array('style' => 'background-color: skyblue; cursor:pointer;');
    $data = file_get_contents($data_file);
    $data = unserialize($data);
    //sort
    if ($sortcol) {
        // Obtain a list of columns
        foreach ($data as $key => $row) {
            $sort1[$key] = $row[$sortcol];
            $data[$key]['key'] = $key;
        }
        // Sort the data
        if ($sortdesc) {
            array_multisort($sort1, SORT_DESC, $data);
        } else {
            array_multisort($sort1, SORT_ASC, $data);
        }
    }
    //filter rows
    $pos--;
    //zero based position
    if ($pos < 0) {
        $pos = 0;
    }
    $poscnt = count($data);
    if ($pos >= $poscnt) {
        $pos = floor(($poscnt - 1) / $pospage) * $pospage;
    }
    $r = 0;
    foreach ($data as $k => $v) {
        if ($r < $pos || $r >= $pos + $pospage) {
            unset($data[$k]);
        }
        $r++;
    }
    require_once "./AjaxDataGrid.class.php";
    $at = new DataGrid($data, "");
    $at->JsClass = $cls;
    $at->pos = $pos + 1;
    //one based position
    $at->pospage = $pospage;
    $at->poscnt = $poscnt;
    $at->SetEvenRowAttribs($even);
    $at->SetOddRowAttribs($odd);
    $at->SetTableAttribs($table);
    $at->SetHeaderAttribs($headerattrib);
    $at->AddColumnReadonly("id", "id[Readonly]");
    $at->AddColumnHidden("col1", "col1[Hidden]");
    $at->AddColumnText("col2", "col2[Text]");
    $at->AddColumnSelect("col3", "col3[Select]", array("1st option", "2nd option", "test ' qoute", "test \" dqoute", "test < lt", "test & amp"));
    $at->AddColumnSelectkey("col4", "col4[Selectkey]", array("key1" => "1st option", "key2" => "2nd option", "key3" => "test ' qoute", "key4" => "test \" dqoute", "key5" => "test < lt", "key6" => "test & amp"));
    $at->AddColumnCheckbox("col5", "col5[Checkbox]");
    $at->AddColumnTextarea("col6", "col6[Textarea]", 200, 100);
    return $at;
}