Example #1
0
function main($imp, $cmd)
{
    global $SIDU;
    if (!$SIDU[1]) {
        $err = @lang(2201);
    } elseif ($SIDU['eng'] == 'pg' && !$SIDU[2]) {
        $err = @lang(2202);
    }
    echo "<form action='imp.php?id={$SIDU['0']},{$SIDU['1']},{$SIDU['2']}' method='post' enctype='multipart/form-data'>\n\t<div class='web'><p class='dot'><b>", @lang(2203), ": <i class='red'>DB = {$SIDU['1']}", $SIDU[2] ? ".{$SIDU['2']}" : "", "</i></b></p>";
    if ($err) {
        echo "<p class='err'>{$err}</p></div></form>";
        return;
    }
    if ($cmd) {
        $SIDU[4] = $imp['tab'];
    }
    if ($SIDU[4]) {
        $res = @tm("SQL", "SELECT * FROM " . @goodname($SIDU[4]) . " LIMIT 1");
        $col = @get_sql_col($res, $SIDU['eng']);
        foreach ($col as $v) {
            $imp['cols'][] = $v[0];
        }
    }
    if (!$imp['col']) {
        $imp['col'] = @implode("\n", $imp['cols']);
    }
    if ($cmd) {
        $err = @valid_data($SIDU, $imp);
        if ($err) {
            echo "<p class='err'>{$err}</p>";
        } else {
            return @save_data($SIDU, $imp);
        }
    }
    if ($SIDU['eng'] == 'my') {
        $sql = "SHOW TABLES from `{$SIDU['1']}`";
    } elseif ($SIDU['eng'] == 'sl') {
        $sql = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY 1";
    } else {
        $sql = "SELECT relname FROM pg_class a,pg_namespace b\nWHERE a.relnamespace=b.oid AND b.nspname='public' AND a.relkind='r' ORDER BY 1";
    }
    $arr = @sql2arr($sql, 1);
    $tabs[0] = @lang(2204);
    foreach ($arr as $v) {
        $tabs[$v] = $v;
    }
    echo "<table><tr><td>", @lang(2205), ":</td><td>", @html_form("select", "imp[tab]", $SIDU[4], "", "", "onchange=\"location='imp.php?id={$SIDU['0']},{$SIDU['1']},{$SIDU['2']},r,'+this.options[this.selectedIndex].value\"", $tabs), "</td></tr>";
    if ($SIDU[4]) {
        echo "<tr><td valign='top'>", @lang(2206), ":</td><td>", @html_form("textarea", "imp[col]", $imp['col'], 350, 90), "</td></tr>";
    }
    echo "<tr><td valign='top'>", @lang(2207), ":</td><td><input type='file' name='f'/> ", @lang(2208, '2MB'), "</td></tr></table>\n\t<p class='dot'><br/><b>", @lang(2209), ":</b></p>\n\t<p class='dot'>", @lang(2210), ": ", @html_form("text", "imp[sepC]", $imp['sepC'] ? $imp['sepC'] : ',', 50), " eg \\t , ; « | »\n\t<br/>", @lang(2211), " ", @html_form("text", "imp[cut1]", $imp['cut1'], 50), " ", @lang(2212), " ", @html_form("text", "imp[cut2]", $imp['cut2'], 50), " ", @lang(2213), "\n\t<br/>", @lang(2214), ": ", @html_form("text", "imp[pk]", $imp['pk'], 150), " eg. c1;c2\n\t<br/>", @html_form("checkbox", "imp[del]", $imp['del'], "", "", "", array(1 => '')), @lang(2215), "\n\t<br/>", @html_form("checkbox", "imp[merge]", $imp['merge'], "", "", "", array(1 => '')), @lang(2216), "\n\t<br/>", @html_form("checkbox", "imp[stop]", $imp['stop'], "", "", "", array(1 => '')), @lang(2217), "</p>\n\t<p>", @html_form("submit", "cmd", @lang(2218)), "</p></div></form>";
}
Example #2
0
function valid_data($SIDU, &$exp, $cmd)
{
    if (!$exp['db'] && !$exp['drop'] && !$exp['desc'] && !$exp['data']) {
        $exp['desc'] = $exp['data'] = 1;
    }
    if ($exp['drop']) {
        $exp['desc'] = 1;
    }
    if ($exp['ext'] != 'html' && $exp['ext'] != 'sql') {
        $exp['ext'] = 'csv';
    }
    //	if (!$cmd) $exp['zip'] = 1;//default save as zip
    $exp['where'] = @trim(@stripslashes($exp['where']));
    if (!$_GET['sql']) {
        if ($SIDU[4]) {
            $exp['tabs'][0] = $SIDU[4];
        } else {
            $exp['tabs'] = @explode(",", $_GET['tab']);
        }
        if ($SIDU['eng'] == 'my') {
            foreach ($exp['tabs'] as $tab) {
                $exp['sql'][] = "SELECT * FROM `{$SIDU['1']}`.`{$tab}`";
            }
        } elseif ($SIDU['eng'] == 'pg') {
            foreach ($exp['tabs'] as $tab) {
                $exp['sql'][] = "SELECT * FROM \"{$SIDU['2']}\".\"{$tab}\"";
            }
        } else {
            foreach ($exp['tabs'] as $tab) {
                $exp['sql'][] = "SELECT * FROM {$tab}";
            }
        }
        if (!$exp['sql'][1]) {
            $res = @tm("SQL", $exp['sql'][0] . " LIMIT 1");
            $col = @get_sql_col($res, $SIDU['eng']);
            foreach ($col as $v) {
                $exp['tab_col'][] = $v[0];
            }
            if ($exp['tab_col'] != $exp['col']) {
                foreach ($exp['col'] as $k => $v) {
                    $exp['col'][$k] = @goodname($v);
                }
                $exp['sql'][0] = "SELECT " . @implode(",", $exp['col']) . @substr($exp['sql'][0], 8);
            }
            if ($exp['where']) {
                $exp['sql'][0] .= " WHERE {$exp['where']}";
            }
        }
    } else {
        $exp['sql'][0] = $_GET['sql'];
    }
}
Example #3
0
function run_sqls()
{
    global $SIDU;
    $conn = $SIDU['conn'][$SIDU[0]];
    $eng = $conn[1];
    $cook = $SIDU['cook'][$SIDU[0]];
    @tm_use_db($cook[1], $cook[2]);
    if ($_GET['sql'] == 'show vars') {
        $_POST['sqlcur'] = $eng == 'pg' ? 'SHOW ALL' : 'SHOW VARIABLES';
    } elseif (@substr($_GET['sql'], 0, 6) == 'FLUSH ') {
        if ($_GET['sql'] == 'FLUSH ALL') {
            $_POST['sqlcur'] = "FLUSH LOGS;\nFLUSH HOSTS;\nFLUSH PRIVILEGES;\nFLUSH TABLES;\nFLUSH STATUS;\nFLUSH DES_KEY_FILE;\nFLUSH QUERY CACHE;\nFLUSH USER_RESOURCES;\nFLUSH TABLES WITH READ LOCK";
        } else {
            $_POST['sqlcur'] = $_GET['sql'];
        }
    } elseif (@substr($_GET['sql'], 0, 9) == 'STATScol:') {
        $_POST['sqlcur'] = "SELECT " . @goodname(@substr($_GET['sql'], 9)) . ",count(*) FROM " . @goodname($cook[4]) . " GROUP BY 1 ORDER BY 2 DESC,1 LIMIT 20";
    } elseif ($_GET['sql']) {
        $_POST['sqlcur'] = $_GET['sql'];
    }
    $arr = @explode(chr(10), @strip($_POST['sqlcur'], 1, 0, 1));
    foreach ($arr as $v) {
        $v = @trim($v);
        if ($v) {
            $arr2[] = $v;
        }
    }
    $txt = @implode(chr(10), $arr2);
    $arr = @explode(";" . chr(10), $txt);
    foreach ($arr as $i => $sql) {
        $time_start = @microtime(true);
        $res = $eng == 'my' ? @mysql_query($sql) : ($eng == 'pg' ? @pg_query($sql) : @sqlite_query($SIDU['dbL'], $sql));
        $time_end = @microtime(true);
        $time = @round(($time_end - $time_start) * 1000);
        $SIDU[5] += $time;
        $err = @sidu_err(1);
        $RES[$i][0] = $sql;
        if ($err) {
            $RES[$i][1] = $err;
            $SIDU[8]++;
        } else {
            $RES[$i][3] = $eng == 'my' ? @mysql_num_rows($res) : ($eng == 'pg' ? @pg_num_rows($res) : @sqlite_num_rows($res));
            if ($eng == 'pg' && !$RES[$i][3]) {
                $RES[$i][2] = @pg_affected_rows($res);
                if (!$RES[$i][2]) {
                    unset($RES[$i][2]);
                }
            }
            //there is no function: sqlite_affected_rows()
            if ($RES[$i][3] === false && $eng == 'my') {
                $RES[$i][2] = @mysql_affected_rows();
            }
            if (!isset($SIDU[6]) && $RES[$i][3] !== false) {
                $SIDU[6] = $i;
                $RES[$i][5] = @get_sql_col($res, $eng);
                $RES[$i][6] = @get_sql_data($res, $eng);
            } elseif ($_POST['sqlmore'] && $RES[$i][3] !== false) {
                $RES[$i][5] = @get_sql_col($res, $eng);
                $RES[$i][6] = @get_sql_data($res, $eng);
            }
            $RES[$i][4] = $time;
        }
        @tm_his_log('S', $sql, $time, $err);
    }
    $SIDU[7] = ++$i;
    $SIDU['RES'] = $RES;
    //reset cookie
    if ($eng == 'my') {
        $db = @mysql_fetch_row(@mysql_query("SELECT database()"));
        if ($db[0] != $cook[1]) {
            $ck = @array($conn[0], $db[0]);
        }
    } elseif ($eng == 'pg') {
        $db[0] = @pg_dbname();
        if ($db[0] != $cook[1]) {
            $ck = @array($conn[0], $db[0]);
        } else {
            //sch
            $sch = pg_fetch_row(pg_query("SHOW search_path"));
            if (@substr($sch[0], 0, 8) == '"$user",') {
                $sch[0] = @substr($sch[0], 8);
            }
            $sch[0] = @str_replace('"', '', $sch[0]);
            if ($sch[0] != $cook[2]) {
                $ck = @array($conn[0], $cook[1], $sch[0]);
            }
        }
    }
    if (isset($ck)) {
        @update_sidu_cook($ck);
    }
}