Beispiel #1
0
function navi()
{
    global $SIDU;
    $conn = $SIDU['conn'][$SIDU[0]];
    $link = @explode(',', $_GET['id']);
    $eng = @array('my' => 'MySQL', 'pg' => 'Postgres', 'sl' => 'SQLite');
    @sidu_sort($SIDU[5], $SIDU[6], $SIDU[7], $SIDU['page']['sortObj']);
    $obj = @array("r" => @lang(1416), "v" => @lang(1417), "S" => @lang(1418), "f" => @lang(1419));
    if ($link[3] != '') {
        if ($link[3] == 'r') {
            echo "<a href='tab-new.php?id={$SIDU['0']},{$SIDU['1']},{$SIDU['2']},{$SIDU['3']},{$SIDU['4']},{$SIDU['5']},{$SIDU['6']}' onclick=\"xwin(this.href,700,500);return false\" ", @html_hkey("=", @lang(1401)), ">", @html_img('img/tool-add'), "</a>{$SIDU['sep']}";
        }
        if ($link[3] == 'r' || $link[3] == 'v') {
            echo "<a href='#' ", @html_hkey("E", @lang(1402)), " onclick='dbexp(\"{$SIDU['0']},{$SIDU['1']},{$SIDU['2']},{$SIDU['3']}\",\"objs[]\")'>", @html_img('img/tool-down'), $SIDU['page']['menuText'] ? @lang(1403) : "", "</a>";
        }
        if ($link[3] == 'r') {
            echo " <a href='imp.php?id={$SIDU['0']},{$SIDU['1']},{$SIDU['2']}' ", @html_hkey("I", @lang(1404)), " onclick='xwin(this.href);return false'>", @html_img('img/tool-imp'), $SIDU['page']['menuText'] ? @lang(1405) : "", "</a>";
        }
        if ($link[3] == 'r') {
            echo " <a href='#' onclick=\"showHide('objTool')\" title='", @lang(1406), "'>", @html_img('img/tool-sys'), $SIDU['page']['menuText'] ? @lang(1407) : "", "</a>\n\t\t\t<a href='#' onclick=\"setv('objcmd','Empty');return (confirm('", @lang(1409), "') ? dataTab.submit() : false)\" ", @html_hkey("-", @lang(1410)), ">", @html_img('img/tool-flush'), $SIDU['page']['menuText'] ? @lang(1408) : "", "</a>";
        }
        echo " <a href='#' onclick=\"setv('objcmd','Drop'); return (confirm('", @lang(1412, $obj[$SIDU[3]]), "') ? dataTab.submit() : false)\" ", @html_hkey("X", @lang(1413)), ">", @html_img('img/tool-x'), $SIDU['page']['menuText'] ? @lang(1411) : "", "</a>\n\t\t\t<a href='" . ($conn[1] == "sl" ? "tab.php?id={$SIDU['0']},{$SIDU['1']},0,r,sqlite_master'" : "#' onclick=\"showHide('DBseek')\"") . " ", @html_hkey("F", @lang(1414)), ">", @html_img('img/tool-find'), $SIDU['page']['menuText'] ? @lang(1415) : "", "</a>{$SIDU['sep']}", @html_img("img/x{$link['3']}"), " <a href='db.php?id={$link['0']},{$link['1']},,,,{$SIDU['5']},{$SIDU['6']}'>{$link['1']}</a>", $link[2] ? " » <a href='db.php?id={$link['0']},{$link['1']},{$link['2']},{$link['3']},,{$SIDU['5']},{$SIDU['6']}'>{$link['2']}</a>" : "", $link[4] != '' ? " » {$link['4']}" : "";
    } else {
        if ($conn[1] == "my") {
            $serv['server'] = @mysql_get_server_info();
        } elseif ($conn[1] == "pg") {
            $serv = @pg_version();
        } else {
            $serv['server'] = @sqlite_libversion();
        }
        echo @html_img("img/eng-{$conn['1']}"), " <b>SIDU 3.0</b> for <b>{$eng[$conn[1]]}</b>\n\t\t{$SIDU['sep']}<a href='" . ($conn[1] == "sl" ? "tab.php?id={$SIDU['0']},{$SIDU['1']},0,r,sqlite_master'" : "#' onclick=\"showHide('DBseek')\"") . " ", @html_hkey("F", @lang(1414)), @html_img('img/tool-find'), "</a>\n\t\t<a href='db.php?id={$link['0']},,,,,{$SIDU['5']},{$SIDU['6']}'><b>", $conn[1] == "sl" ? "SQLite" : "{$conn['3']}@{$conn['2']}", "</b></a> v {$serv['server']}\n\t\t{$SIDU['sep']} ", @date("Y-m-d H:i:s");
    }
}
Beispiel #2
0
function init_tab(&$SIDU, $link, $conn)
{
    if ($conn[1] == "my") {
        //0name 1type 2null 3defa 4maxchar 5extra 6comm 7pk 8align 9pos
        $res = @tm("SQL", "SELECT COLUMN_NAME,COLUMN_TYPE,IS_NULLABLE,COLUMN_DEFAULT,\nifnull(CHARACTER_MAXIMUM_LENGTH,NUMERIC_PRECISION),EXTRA,COLUMN_COMMENT,\nCOLUMN_KEY,if(NUMERIC_PRECISION IS NULL,'','i'),ORDINAL_POSITION\nFROM information_schema.COLUMNS\nWHERE TABLE_SCHEMA='{$SIDU['1']}' AND TABLE_NAME='{$SIDU['4']}'\nORDER BY ORDINAL_POSITION");
        while ($row = @mysql_fetch_row($res)) {
            $col[] = $row;
            if ($row[7] == 'PRI') {
                $SIDU['pk'][] = $row[9] - 1;
            }
        }
        $num = @mysql_fetch_row(@tm("SQL", "SELECT COUNT(*) FROM `{$link['1']}`.`{$link['4']}`"));
    } elseif ($conn[1] == 'sl') {
        $res = @tm("SQL", "pragma table_info({$link['4']})");
        while ($row = @sqlite_fetch_array($res)) {
            if ($row['type'] == 'integer') {
                $row['type'] = 'int';
            }
            if ($row['pk']) {
                $SIDU['pk'][] = $row['cid'];
            }
            $col[] = @array($row['name'], $row['type'], $row['notnull'] ? 'NULL' : 'YES', $row['dflt_value'], '', '', '', $row['pk'] ? 'PRI' : '', "", $row['cid'] + 1);
        }
        $num = @sqlite_fetch_array(@tm("SQL", "SELECT COUNT(*) FROM {$link['4']}"));
    } else {
        $tab = @pg_fetch_row(@tm("SQL", "SELECT a.oid,a.relnamespace,a.relhasoids,obj_description(a.oid,'pg_class')\nFROM pg_class a,pg_namespace b WHERE a.relkind='{$link['3']}' AND a.relnamespace=b.oid\nAND a.relname='{$link['4']}' AND b.nspname='{$link['2']}'"));
        $SIDU['tabinfo'] = $tab;
        $defa = @sql2arr("SELECT adnum,adsrc FROM pg_attrdef WHERE adrelid={$tab['0']}", 2);
        $defaRaw = $defa;
        foreach ($defa as $k => $v) {
            if (@substr($v, 0, 9) != "nextval('") {
                $rowx = @explode("::", $v);
                if (@substr($rowx[0], 0, 1) == "'" && @substr($rowx[0], -1) == "'") {
                    $rowx[0] = @substr($rowx[0], 1, -1);
                }
                $rowx[0] = @str_replace("''", "'", $rowx[0]);
                $defa[$k] = $rowx[0];
            }
        }
        if ($SIDU['page']['oid'] && $tab[2] == 't') {
            $col[0] = @array("oid", "oid", 't');
            $hasOID = "oid,";
        } else {
            $colX = -1;
        }
        $typ = @sql2arr("SELECT oid,typname FROM pg_type", 2);
        $res = @tm("SQL", "SELECT attname,atttypid,attnotnull,atthasdef,\nCASE attlen WHEN -1 THEN atttypmod ELSE attlen END,\n'','','','',attnum,format_type(atttypid,atttypmod) FROM pg_attribute\nWHERE attrelid={$tab['0']} AND attnum>0 AND attisdropped=FALSE ORDER BY attnum");
        while ($row = @pg_fetch_row($res)) {
            $row[3] = $row[3] == 't' ? $defa[$row[9]] : '';
            $row[1] = $typ[$row[1]];
            if ($row[1] == "numeric") {
                $row[1] = $row[10];
            } elseif ($row[1] == 'int2') {
                $row[1] = "smallint";
            } elseif ($row[1] == 'int4') {
                $row[1] = "int";
            } elseif ($row[1] == 'int8') {
                $row[1] = "bigint";
            } elseif ($row[1] == 'bpchar') {
                $row[1] = "char";
            }
            if ($row[4] > 4 && ($row[1] == 'varchar' || $row[1] == 'char')) {
                $row[1] .= "(" . ($row[4] - 4) . ")";
            }
            if (@substr($row[3], 0, 9) == "nextval('") {
                $row[1] = $row[1] == "int" ? "serial" : "bigserial";
            }
            $row[11] = $defaRaw[$row[9]];
            //only used for default ''::varchar etc
            $col[] = $row;
        }
        $res = @tm("SQL", "SELECT conkey,contype FROM pg_constraint\nWHERE connamespace={$tab['1']} AND conrelid={$tab['0']}");
        while ($row = @pg_fetch_row($res)) {
            //pk uk fk
            $pucf = @explode(",", @substr($row[0], 1, -1));
            foreach ($pucf as $v) {
                $col[$v + $colX][7] = $col[$v + $colX][7] ? $col[$v + $colX][7] . ",{$row['1']}" : $row[1];
                if ($row[1] == 'p') {
                    $SIDU['pk'][] = $v + $colX;
                }
            }
        }
        $num = @pg_fetch_row(@tm("SQL", "SELECT COUNT(*) FROM \"{$link['2']}\".\"{$link['4']}\""));
    }
    $SIDU[10] += $num[0];
    $SIDU['col'] = $col;
    if ($_GET['desc']) {
        //desc
        if ($conn[1] == 'pg') {
            //set col comm
            $res = @tm("SQL", "SELECT objsubid,description FROM pg_description\nWHERE objoid={$tab['0']} AND objsubid>0");
            while ($row = @pg_fetch_row($res)) {
                $SIDU['col'][$row[0] + $colX][6] = $row[1];
            }
        }
        return;
    }
    $SIDU['gridShow'] = $_POST['gridShow'];
    $MODE = @explode('.', $_COOKIE['SIDUMODE']);
    //0lang 1gridmode 2pgsize=sidu9
    $SIDU['gridMode'] = $MODE[1];
    if ($MODE[2] < -1 || !$MODE[2]) {
        $MODE[2] = 15;
    }
    $SIDU[9] = $MODE[2];
    $SIDU[8] = @ceil($_POST['sidu8']);
    if ($SIDU[8] < 0) {
        $SIDU[8] = 0;
    }
    $SIDU[7] = $_POST['sidu7'];
    //sort
    if (@substr($SIDU[7], 0, 4) == 'del:') {
        $SIDU[7] = @substr($SIDU[7], 4);
        if ($SIDU[5] == $SIDU[7] || $SIDU[5] == "{$SIDU['7']} desc") {
            $SIDU[5] = $SIDU[7] = '';
        } elseif ($SIDU[6] == $SIDU[7] || $SIDU[6] == "{$SIDU['7']} desc") {
            $SIDU[6] = $SIDU[7] = '';
        } else {
            $SIDU[7] = '';
        }
    }
    $SIDU['f'] = @strip($_POST['f'], 1, 0, 1);
    @sidu_sort($SIDU[5], $SIDU[6], $SIDU[7], $SIDU['page']['sortData']);
    $strSort = $SIDU[5] ? " ORDER BY {$SIDU['5']}" . ($SIDU[6] ? ",{$SIDU['6']}" : "") : ($SIDU[6] ? " ORDER BY {$SIDU['6']}" : "");
    foreach ($SIDU['f'] as $k => $v) {
        if ($k === 'sql' && $v) {
            $whereSQL = " AND " . $SIDU['f']['sql'];
        } elseif ($v != '') {
            $where .= " AND " . $SIDU['col'][$k][0] . " {$v}";
        }
    }
    $where .= $whereSQL;
    if (!$strSort && (!$where || !@stripos($where, " order by "))) {
        $strSort = " ORDER BY 1 DESC";
    }
    if ($where) {
        $where = " WHERE " . @substr($where, 5);
        if ($conn[1] == 'my') {
            $res = @tm("SQL", "SELECT COUNT(*) FROM `{$SIDU['1']}`.`{$SIDU['4']}`{$where}");
            $row = @mysql_fetch_row($res);
        } elseif ($conn[1] == 'pg') {
            $res = @tm("SQL", "SELECT COUNT(*) FROM \"{$SIDU['2']}\".\"{$SIDU['4']}\"{$where}");
            $row = @pg_fetch_row($res);
        } else {
            $res = @tm("SQL", "SELECT COUNT(*) FROM {$SIDU['4']}{$where}");
            $row = @sqlite_fetch_array($res);
        }
        $SIDU[10] = $row[0];
    }
    if ($_POST['cmd'] == 'p1') {
        $SIDU[8] = 0;
    } elseif ($SIDU[9] != -1) {
        if ($_POST['cmd'] == 'pback') {
            $SIDU[8] -= $SIDU[9];
        } elseif ($_POST['cmd'] == 'pnext') {
            $SIDU[8] += $SIDU[9];
        } elseif ($_POST['cmd'] == 'plast') {
            $SIDU[8] = $SIDU[10] - $SIDU[9];
        }
        if ($SIDU[8] > $SIDU[10]) {
            $SIDU[8] = $SIDU[10] - $SIDU[9];
        }
        if ($SIDU[8] < 0) {
            $SIDU[8] = 0;
        }
    }
    if ($SIDU[9] != -1) {
        $limit = " LIMIT {$SIDU['9']}" . ($SIDU[8] ? " OFFSET {$SIDU['8']}" : "");
    }
    if ($conn[1] == 'my') {
        $res = @tm("SQL", "SELECT * FROM `{$SIDU['1']}`.`{$SIDU['4']}`{$where}{$strSort}{$limit}");
        while ($row = @mysql_fetch_row($res)) {
            $arr[] = $row;
        }
    } elseif ($conn[1] == 'pg') {
        $res = @tm("SQL", "SELECT {$hasOID}* FROM \"{$SIDU['2']}\".\"{$SIDU['4']}\"{$where}{$strSort}{$limit}");
        while ($row = @pg_fetch_row($res)) {
            $arr[] = $row;
        }
    } else {
        $res = @tm("SQL", "SELECT * FROM {$SIDU['4']}{$where}{$strSort}{$limit}");
        while ($row = @sqlite_fetch_array($res, SQLITE_NUM)) {
            $arr[] = $row;
        }
    }
    $SIDU['data'] = $arr;
    if ($conn[1] != 'my') {
        @init_pg_col_align($SIDU['data'], $SIDU['col']);
    }
    if ($_POST['hideCol'] != '') {
        $_POST['g'][$_POST['hideCol']] = -1;
    }
    @init_col_width($SIDU);
}