Example #1
0
<?php

$TABLE = $_GET["table"];
$fields = fields($TABLE);
if (!$fields) {
    $error = error();
}
$table_status = table_status1($TABLE, true);
page_header(($fields && is_view($table_status) ? lang('View') : lang('Table')) . ": " . h($TABLE), $error);
$adminer->selectLinks($table_status);
$comment = $table_status["Comment"];
if ($comment != "") {
    echo "<p>" . lang('Comment') . ": " . h($comment) . "\n";
}
if ($fields) {
    echo "<table cellspacing='0'>\n";
    echo "<thead><tr><th>" . lang('Column') . "<td>" . lang('Type') . (support("comment") ? "<td>" . lang('Comment') : "") . "</thead>\n";
    foreach ($fields as $field) {
        echo "<tr" . odd() . "><th>" . h($field["field"]);
        echo "<td title='" . h($field["collation"]) . "'>" . h($field["full_type"]) . ($field["null"] ? " <i>NULL</i>" : "") . ($field["auto_increment"] ? " <i>" . lang('Auto Increment') . "</i>" : "");
        echo isset($field["default"]) ? " [<b>" . h($field["default"]) . "</b>]" : "";
        echo support("comment") ? "<td>" . nbsp($field["comment"]) : "";
        echo "\n";
    }
    echo "</table>\n";
}
if (!is_view($table_status)) {
    if (support("indexes")) {
        echo "<h3 id='indexes'>" . lang('Indexes') . "</h3>\n";
        $indexes = indexes($TABLE);
        if ($indexes) {
Example #2
0
<?php

$TABLE = $_GET["select"];
$table_status = table_status1($TABLE);
$indexes = indexes($TABLE);
$fields = fields($TABLE);
$foreign_keys = column_foreign_keys($TABLE);
$oid = "";
if ($table_status["Oid"]) {
    $oid = $jush == "sqlite" ? "rowid" : "oid";
    $indexes[] = array("type" => "PRIMARY", "columns" => array($oid));
}
parse_str($_COOKIE["adminer_import"], $adminer_import);
$rights = array();
// privilege => 0
$columns = array();
// selectable columns
$text_length = null;
foreach ($fields as $key => $field) {
    $name = $adminer->fieldName($field);
    if (isset($field["privileges"]["select"]) && $name != "") {
        $columns[$key] = html_entity_decode(strip_tags($name), ENT_QUOTES);
        if (is_shortable($field)) {
            $text_length = $adminer->selectLengthProcess();
        }
    }
    $rights += $field["privileges"];
}
list($select, $group) = $adminer->selectColumnsProcess($columns, $indexes);
$is_group = count($group) < count($select);
$where = $adminer->selectSearchProcess($fields, $indexes);
Example #3
0
/** Print edit data form
* @param string
* @param array
* @param mixed
* @param bool
* @return null
*/
function edit_form($TABLE, $fields, $row, $update)
{
    global $adminer, $jush, $token, $error;
    $table_name = $adminer->tableName(table_status1($TABLE, true));
    page_header($update ? lang('Edit') : lang('Insert'), $error, array("select" => array($TABLE, $table_name)), $table_name);
    if ($row === false) {
        echo "<p class='error'>" . lang('No rows.') . "\n";
    }
    ?>
<form action="" method="post" enctype="multipart/form-data" id="form">
<?php 
    if (!$fields) {
        echo "<p class='error'>" . lang('You have no privileges to update this table.') . "\n";
    } else {
        echo "<table cellspacing='0' onkeydown='return editingKeydown(event);'>\n";
        foreach ($fields as $name => $field) {
            echo "<tr><th>" . $adminer->fieldName($field);
            $default = $_GET["set"][bracket_escape($name)];
            if ($default === null) {
                $default = $field["default"];
                if ($field["type"] == "bit" && preg_match("~^b'([01]*)'\$~", $default, $regs)) {
                    $default = $regs[1];
                }
            }
            $value = $row !== null ? $row[$name] != "" && $jush == "sql" && preg_match("~enum|set~", $field["type"]) ? is_array($row[$name]) ? array_sum($row[$name]) : +$row[$name] : $row[$name] : (!$update && $field["auto_increment"] ? "" : (isset($_GET["select"]) ? false : $default));
            if (!$_POST["save"] && is_string($value)) {
                $value = $adminer->editVal($value, $field);
            }
            $function = $_POST["save"] ? (string) $_POST["function"][$name] : ($update && $field["on_update"] == "CURRENT_TIMESTAMP" ? "now" : ($value === false ? null : ($value !== null ? '' : 'NULL')));
            if (preg_match("~time~", $field["type"]) && $value == "CURRENT_TIMESTAMP") {
                $value = "";
                $function = "now";
            }
            input($field, $value, $function);
            echo "\n";
        }
        if (!support("table")) {
            echo "<tr>" . "<th><input name='field_keys[]' onkeyup='keyupChange.call(this);' onchange='fieldChange(this);' value=''>" . "<td class='function'>" . html_select("field_funs[]", $adminer->editFunctions(array("null" => isset($_GET["select"])))) . "<td><input name='field_vals[]'>" . "\n";
        }
        echo "</table>\n";
    }
    echo "<p>\n";
    if ($fields) {
        echo "<input type='submit' value='" . lang('Save') . "'>\n";
        if (!isset($_GET["select"])) {
            echo "<input type='submit' name='insert' value='" . ($update ? lang('Save and continue edit') . "' onclick='return !ajaxForm(this.form, \"" . lang('Saving') . '...", this)' : lang('Save and insert next')) . "' title='Ctrl+Shift+Enter'>\n";
        }
    }
    echo $update ? "<input type='submit' name='delete' value='" . lang('Delete') . "'" . confirm() . ">\n" : ($_POST || !$fields ? "" : "<script type='text/javascript'>focus(document.getElementById('form').getElementsByTagName('td')[1].firstChild);</script>\n");
    if (isset($_GET["select"])) {
        hidden_fields(array("check" => (array) $_POST["check"], "clone" => $_POST["clone"], "all" => $_POST["all"]));
    }
    ?>
<input type="hidden" name="referer" value="<?php 
    echo h(isset($_POST["referer"]) ? $_POST["referer"] : $_SERVER["HTTP_REFERER"]);
    ?>
">
<input type="hidden" name="save" value="1">
<input type="hidden" name="token" value="<?php 
    echo $token;
    ?>
">
</form>
<?php 
}
Example #4
0
            }
            queries_redirect($location, lang('Item has been updated.'), $driver->update($TABLE, $set, $query_where, !$unique_array));
            if (is_adminer_ajax()) {
                page_headers();
                page_messages($error);
                exit;
            }
        } else {
            $result = $driver->insert($TABLE, $set);
            $last_id = $result ? last_id() : 0;
            queries_redirect($location, lang('Item%s has been inserted.', $last_id ? " {$last_id}" : ""), $result);
            //! link
        }
    }
}
$table_name = $adminer->tableName(table_status1($TABLE, true));
page_header($update ? lang('Edit') : lang('Insert'), $error, array("select" => array($TABLE, $table_name)), $table_name);
$row = null;
if ($_POST["save"]) {
    $row = (array) $_POST["fields"];
} elseif ($where) {
    $select = array();
    foreach ($fields as $name => $field) {
        if (isset($field["privileges"]["select"])) {
            $as = convert_field($field);
            if ($_POST["clone"] && $field["auto_increment"]) {
                $as = "''";
            }
            if ($jush == "sql" && preg_match("~enum|set~", $field["type"])) {
                $as = "1*" . idf_escape($name);
            }