Example #1
0
    function head()
    {
        if (!isset($_GET['sql'])) {
            return;
        }
        $suggests = array();
        foreach ($this->keywords as $keyword) {
            $suggests[] = "{$keyword} ";
        }
        foreach (array_keys(tables_list()) as $table) {
            $suggests[] = $table;
            foreach (fields($table) as $field => $foo) {
                $suggests[] = "{$table}.{$field} ";
            }
        }
        ?>
<script type="text/javascript" src="static/jquery.min.js"></script>
<script type="text/javascript" src="static/tabcomplete/tabcomplete.js"></script>
<style>.hint { color: #bdc3c7; }</style>
<script type="text/javascript">
$(function(){
	$('.sqlarea').tabcomplete(<?php 
        echo json_encode($suggests);
        ?>
);
});
</script>
<?php 
    }
Example #2
0
    function head()
    {
        if (!isset($_GET['sql'])) {
            return;
        }
        $tables = array_keys(tables_list());
        $suggests = array_merge($this->keywords, $tables);
        foreach ($tables as $table) {
            foreach (fields($table) as $field => $foo) {
                $suggests[] = "{$table}.{$field}";
            }
        }
        ?>
<script type="text/javascript" src="static/jquery.min.js"></script>
<script type="text/javascript" src="static/jquery.a-tools.js"></script>
<script type="text/javascript" src="static/jquery.asuggest.js"></script>
<script type="text/javascript">
$(function(){
	if (navigator.appName == 'Microsoft Internet Explorer') {
		return;
	}

    $('.sqlarea').attr('onkeydown', '').asuggest(['<?php 
        echo implode("', '", str_replace("'\\", '', $suggests));
        ?>
'], {
        stopSuggestionKeys: [$.asuggestKeys.TAB, $.asuggestKeys.RETURN, $.asuggestKeys.SPACE, 190 /* PERIOD */],
        ignoreCase: true
    });
});
</script>
<?php 
    }
    function head()
    {
        if (!isset($_GET['sql'])) {
            return;
        }
        $suggests = $tables = array_keys(tables_list());
        foreach ($tables as $table) {
            foreach (fields($table) as $field => $foo) {
                $suggests[] = "{$table}.{$field}";
            }
        }
        ?>
<script type="text/javascript" src="static/jquery.min.js"></script>
<script type="text/javascript" src="static/tabcomplete/tabcomplete.js"></script>
<style>.hint { color: #bdc3c7; }</style>
<script type="text/javascript">
$(function(){
	$('.sqlarea').tabcomplete(['<?php 
        echo implode("', '", str_replace("'\\", '', $suggests));
        ?>
']);
});
</script>
<?php 
    }
Example #4
0
<input type="hidden" name="token" value="<?php 
echo $token;
?>
">

<table cellspacing="0">
<?php 
$prefixes = array();
if (DB != "") {
    $checked = $TABLE != "" ? "" : " checked";
    echo "<thead><tr>";
    echo "<th style='text-align: left;'><label class='block'><input type='checkbox' id='check-tables'{$checked} onclick='formCheck(this, /^tables\\[/);'>" . lang('Tables') . "</label>";
    echo "<th style='text-align: right;'><label class='block'>" . lang('Data') . "<input type='checkbox' id='check-data'{$checked} onclick='formCheck(this, /^data\\[/);'></label>";
    echo "</thead>\n";
    $views = "";
    $tables_list = tables_list();
    foreach ($tables_list as $name => $type) {
        $prefix = preg_replace('~_.*~', '', $name);
        $checked = $TABLE == "" || $TABLE == (substr($TABLE, -1) == "%" ? "{$prefix}%" : $name);
        //! % may be part of table name
        $print = "<tr><td>" . adminer_checkbox("tables[]", $name, $checked, $name, "checkboxClick(event, this); formUncheck('check-tables');", "block");
        if ($type !== null && !preg_match('~table~i', $type)) {
            $views .= "{$print}\n";
        } else {
            echo "{$print}<td align='right'><label class='block'><span id='Rows-" . h($name) . "'></span>" . adminer_checkbox("data[]", $name, $checked, "", "checkboxClick(event, this); formUncheck('check-data');") . "</label>\n";
        }
        $prefixes[$prefix]++;
    }
    echo $views;
    if ($tables_list) {
        echo "<script type='text/javascript'>ajaxSetHtml('" . is_adminer_escape(ME) . "script=db');</script>\n";
Example #5
0
 function table_status($name = "", $fast = false)
 {
     $return = array();
     foreach (tables_list() as $table => $type) {
         $return[$table] = array("Name" => $table);
         if ($name == $table) {
             return $return[$table];
         }
     }
     return $return;
 }
 function table_status($name = "", $fast = false)
 {
     global $connection;
     $return = array();
     $data = tables_list();
     foreach ($data as $index => $val) {
         $index = trim($index);
         $return[$index] = array('Name' => $index, 'Engine' => 'standard');
         if ($name == $index) {
             return $return[$index];
         }
     }
     return $return;
 }
Example #7
0
 function count_tables($databases)
 {
     foreach ($databases as $db) {
         return array($db => count(tables_list()));
     }
 }
Example #8
0
function entry_audit()
{
    global $_STATE;
    if (!isset($_POST["chkTable"])) {
        $_STATE->msgStatus = "No tables were loaded";
        return;
    }
    tables_list();
    try {
        //Use an unprintable char as the delimiter:
        $db = new db_connect("\r" . $_POST["txtName"] . "\r" . $_POST["txtPswd"]);
    } catch (PDOException $e) {
        $_STATE->msgStatus = "Connection failed: " . $e->getMessage();
        return;
    }
    foreach ($_POST["chkTable"] as $ID => $value) {
        if (!array_key_exists($ID, $_STATE->records)) {
            throw_the_bum_out(NULL, "Evicted(" . __LINE__ . "): invalid table name " . $_POST["chkTable"]);
        }
        if ($value == "on") {
            $_STATE->msgStatus .= $ID;
            if ($_STATE->records[$ID]->MDBname == "") {
                throw_the_bum_out(NULL, "Evicted(" . __LINE__ . "): non-loadable table " . $_POST["chkTable"]);
            }
            if (!load($db, $_STATE->records[$ID])) {
                $_STATE->msgStatus .= "<br>attempted load of " . $GLOBALS["MDBload_path"] . $_STATE->records[$ID]->MDBname . ".csv" . " failed";
            }
            $_STATE->msgStatus .= "<br>";
        }
    }
    $db = NULL;
    return;
}
Example #9
0
 function table_status($name = "", $fast = false)
 {
     $return = tables_list();
     if ($return) {
         foreach ($return as $key => $type) {
             // _stats have just info about database
             $return[$key] = array("Name" => $key, "Engine" => $type);
         }
         if ($name != "") {
             return $return[$name];
         }
     }
     return $return;
 }
Example #10
0
 /** Rename database from DB
  * @param string new name
  * @param string
  * @return bool
  */
 function rename_database($name, $collation)
 {
     $return = false;
     if (create_database($name, $collation)) {
         //! move triggers
         $rename = array();
         foreach (tables_list() as $table => $type) {
             $rename[] = table($table) . " TO " . idf_escape($name) . "." . table($table);
         }
         $return = !$rename || queries("RENAME TABLE " . implode(", ", $rename));
         if ($return) {
             queries("DROP DATABASE " . idf_escape(DB));
         }
         restart_session();
         set_session("dbs", null);
     }
     return $return;
 }
Example #11
0
function entry_audit()
{
    global $_STATE;
    if (!isset($_POST["chkTable"])) {
        $_STATE->msgStatus = "No tables were refreshed";
        return;
    }
    if ($_POST["txtCount"] != "" && !is_numeric($_POST["txtCount"])) {
        $_STATE->msgStatus = "Invalid 'Stop after' count";
        return;
    }
    tables_list();
    try {
        //Use an unprintable char as the delimiter:
        $db = new db_connect("\r" . $_POST["txtName"] . "\r" . $_POST["txtPswd"]);
    } catch (PDOException $e) {
        $_STATE->msgStatus = "Connection failed: " . $e->getMessage();
        return;
    }
    foreach ($_POST["chkTable"] as $ID => $value) {
        if (!array_key_exists($ID, $_STATE->records)) {
            throw_the_bum_out(NULL, "Evicted(" . __LINE__ . "): invalid table name " . $_POST["chkTable"]);
        }
        if ($value == "on") {
            $_STATE->msgStatus .= $ID;
            if (!refresh($db, $_STATE->records[$ID])) {
                $_STATE->msgStatus .= ": attempted refresh failed";
            }
            $_STATE->msgStatus .= "<br>";
        }
    }
    $db = NULL;
    return;
}
Example #12
0
function upgrade(&$new_date)
{
    global $_DB, $_STATE;
    //	$diff = date_diff($_STATE->fields["Close Date"]->value, COM_NOW(), true);
    //	if ($diff->m > 2) {
    $sql = "SELECT MAX(logdate) AS max_date FROM " . $_DB->prefix . "b00_timelog;";
    $stmt = $_DB->query($sql);
    $row = $stmt->fetchObject();
    $max_date = new DateTime($row->max_date);
    $stmt->closeCursor();
    $diff = date_diff($max_date, $new_date->value, true);
    $interval = new DateInterval("P" . $diff->days . "D");
    $diff = 1;
    if ($max_date > $new_date->value) {
        $diff = -1;
    }
    tables_list();
    foreach ($_POST["chkDate"] as $chkDate) {
        up_date($chkDate, $interval, $diff);
    }
    echo "<br>Done!";
    exit;
}
    /** Prints navigation after Adminer title
     * @param string can be "auth" if there is no database connection, "db" if there is no database selected, "ns" with invalid schema
     * @return null
     */
    function navigation($missing)
    {
        global $VERSION, $connection, $token, $jush, $drivers;
        ?>
<h1>
<?php 
        echo $this->name();
        ?>
 <span class="version"><?php 
        echo $VERSION;
        ?>
</span>
<a href="http://www.adminer.org/#download" id="version"><?php 
        echo version_compare($VERSION, $_COOKIE["adminer_version"]) < 0 ? h($_COOKIE["adminer_version"]) : "";
        ?>
</a>
</h1>
<?php 
        if ($missing == "auth") {
            $first = true;
            foreach ((array) $_SESSION["pwds"] as $driver => $servers) {
                foreach ($servers as $server => $usernames) {
                    foreach ($usernames as $username => $password) {
                        if (isset($password)) {
                            if ($first) {
                                echo "<p onclick='eventStop(event);'>\n";
                                $first = false;
                            }
                            echo "<a href='" . h(auth_url($driver, $server, $username)) . "'>({$drivers[$driver]}) " . h($username . ($server != "" ? "@{$server}" : "")) . "</a><br>\n";
                        }
                    }
                }
            }
        } else {
            $databases = get_databases();
            ?>
<form action="" method="post">
<p class="logout">
<?php 
            if (DB == "" || !$missing) {
                echo "<a href='" . h(ME) . "sql='" . bold(isset($_GET["sql"])) . ">" . lang('SQL command') . "</a>\n";
                if (support("dump")) {
                    echo "<a href='" . h(ME) . "dump=" . urlencode(isset($_GET["table"]) ? $_GET["table"] : $_GET["select"]) . "' id='dump'" . bold(isset($_GET["dump"])) . ">" . lang('Dump') . "</a>\n";
                }
            }
            ?>
<input type="submit" name="logout" value="<?php 
            echo lang('Logout');
            ?>
" onclick="eventStop(event);">
<input type="hidden" name="token" value="<?php 
            echo $token;
            ?>
">
</p>
</form>
<form action="">
<p>
<?php 
            hidden_fields_get();
            echo $databases ? html_select("db", array("" => "(" . lang('database') . ")") + $databases, DB, "this.form.submit();") : '<input name="db" value="' . h(DB) . '">';
            ?>
<input type="submit" value="<?php 
            echo lang('Use');
            ?>
"<?php 
            echo $databases ? " class='hidden'" : "";
            ?>
 onclick="eventStop(event);">
<?php 
            if ($missing != "db" && DB != "" && $connection->select_db(DB)) {
                if (support("scheme")) {
                    echo "<br>" . html_select("ns", array("" => "(" . lang('schema') . ")") + schemas(), $_GET["ns"], "this.form.submit();");
                    if ($_GET["ns"] != "") {
                        set_schema($_GET["ns"]);
                    }
                }
                if ($_GET["ns"] !== "" && !$missing) {
                    echo '<p><a href="' . h(ME) . 'create="' . bold($_GET["create"] === "") . ">" . lang('Create new table') . "</a>\n";
                    $tables = tables_list();
                    if (!$tables) {
                        echo "<p class='message'>" . lang('No tables.') . "\n";
                    } else {
                        $this->tablesPrint($tables);
                        $links = array();
                        foreach ($tables as $table => $type) {
                            $links[] = preg_quote($table, '/');
                        }
                        echo "<script type='text/javascript'>\n";
                        echo "var jushLinks = { {$jush}: [ '" . js_adminer_escape(ME) . "table=\$&', /\\b(" . implode("|", $links) . ")\\b/g ] };\n";
                        foreach (array("bac", "bra", "sqlite_quo", "mssql_bra") as $val) {
                            echo "jushLinks.{$val} = jushLinks.{$jush};\n";
                        }
                        echo "</script>\n";
                    }
                }
            }
            echo isset($_GET["sql"]) ? '<input type="hidden" name="sql" value="">' : (isset($_GET["schema"]) ? '<input type="hidden" name="schema" value="">' : (isset($_GET["dump"]) ? '<input type="hidden" name="dump" value="">' : ""));
            echo "</p></form>\n";
        }
    }