/** Print columns box in select * @param array result of selectColumnsProcess()[0] * @param array selectable columns * @return null */ function selectColumnsPrint($select, $columns) { global $functions, $grouping; print_fieldset("select", lang('Select'), $select); $i = 0; $select[""] = array(); foreach ($select as $key => $val) { $val = $_GET["columns"][$key]; $column = select_input(" name='columns[{$i}][col]' onchange='" . ($key !== "" ? "selectFieldChange(this.form)" : "selectAddRow(this)") . ";'", $columns, $val["col"]); echo "<div>" . ($functions || $grouping ? "<select name='columns[{$i}][fun]' onchange='helpClose();" . ($key !== "" ? "" : " this.nextSibling.nextSibling.onchange();") . "'" . on_help("getTarget(event).value && getTarget(event).value.replace(/ |\$/, '(') + ')'", 1) . ">" . optionlist(array(-1 => "") + array_filter(array(lang('Functions') => $functions, lang('Aggregation') => $grouping)), $val["fun"]) . "</select>" . "({$column})" : $column) . "</div>\n"; $i++; } echo "</div></fieldset>\n"; }
/** Print edit input field * @param array one field from fields() * @param mixed * @param string * @return null */ function input($field, $value, $function) { global $connection, $types, $adminer, $jush; $name = h(bracket_escape($field["field"])); echo "<td class='function'>"; if (is_array($value) && !$function) { $args = array($value); if (version_compare(PHP_VERSION, 5.4) >= 0) { $args[] = JSON_PRETTY_PRINT; } $value = call_user_func_array('json_encode', $args); //! requires PHP 5.2 $function = "json"; } $reset = $jush == "mssql" && $field["auto_increment"]; if ($reset && !$_POST["save"]) { $function = null; } $functions = (isset($_GET["select"]) || $reset ? array("orig" => lang('original')) : array()) + $adminer->editFunctions($field); $attrs = " name='fields[{$name}]'"; if ($field["type"] == "enum") { echo nbsp($functions[""]) . "<td>" . $adminer->editInput($_GET["edit"], $field, $attrs, $value); } else { $first = 0; foreach ($functions as $key => $val) { if ($key === "" || !$val) { break; } $first++; } $onchange = $first ? " onchange=\"var f = this.form['function[" . h(js_escape(bracket_escape($field["field"]))) . "]']; if ({$first} > f.selectedIndex) f.selectedIndex = {$first};\" onkeyup='keyupChange.call(this);'" : ""; $attrs .= $onchange; $has_function = in_array($function, $functions) || isset($functions[$function]); echo (count($functions) > 1 ? "<select name='function[{$name}]' onchange='functionChange(this);'" . on_help("getTarget(event).value.replace(/^SQL\$/, '')", 1) . ">" . optionlist($functions, $function === null || $has_function ? $function : "") . "</select>" : nbsp(reset($functions))) . '<td>'; $input = $adminer->editInput($_GET["edit"], $field, $attrs, $value); // usage in call is without a table if ($input != "") { echo $input; } elseif ($field["type"] == "set") { //! 64 bits preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches); foreach ($matches[1] as $i => $val) { $val = stripcslashes(str_replace("''", "'", $val)); $checked = is_int($value) ? $value >> $i & 1 : in_array($val, explode(",", $value), true); echo " <label><input type='checkbox' name='fields[{$name}][{$i}]' value='" . (1 << $i) . "'" . ($checked ? ' checked' : '') . "{$onchange}>" . h($adminer->editVal($val, $field)) . '</label>'; } } elseif (preg_match('~blob|bytea|raw|file~', $field["type"]) && ini_bool("file_uploads")) { echo "<input type='file' name='fields-{$name}'{$onchange}>"; } elseif (($text = preg_match('~text|lob~', $field["type"])) || preg_match("~\n~", $value)) { if ($text && $jush != "sqlite") { $attrs .= " cols='50' rows='12'"; } else { $rows = min(12, substr_count($value, "\n") + 1); $attrs .= " cols='30' rows='{$rows}'" . ($rows == 1 ? " style='height: 1.2em;'" : ""); // 1.2em - line-height } echo "<textarea{$attrs}>" . h($value) . '</textarea>'; } elseif ($function == "json") { echo "<textarea{$attrs} cols='50' rows='12' class='jush-js'>" . h($value) . '</textarea>'; } else { // int(3) is only a display hint $maxlength = !preg_match('~int~', $field["type"]) && preg_match('~^(\\d+)(,(\\d+))?$~', $field["length"], $match) ? (preg_match("~binary~", $field["type"]) ? 2 : 1) * $match[1] + ($match[3] ? 1 : 0) + ($match[2] && !$field["unsigned"] ? 1 : 0) : ($types[$field["type"]] ? $types[$field["type"]] + ($field["unsigned"] ? 0 : 1) : 0); if ($jush == 'sql' && $connection->server_info >= 5.6 && preg_match('~time~', $field["type"])) { $maxlength += 7; // microtime } // type='date' and type='time' display localized value which may be confusing, type='datetime' uses 'T' as date and time separator echo "<input" . ((!$has_function || $function === "") && preg_match('~(?<!o)int~', $field["type"]) && !preg_match('~\\[\\]~', $field["full_type"]) ? " type='number'" : "") . " value='" . h($value) . "'" . ($maxlength ? " maxlength='{$maxlength}'" : "") . (preg_match('~char|binary~', $field["type"]) && $maxlength > 20 ? " size='40'" : "") . "{$attrs}>"; } } }
?> <input type="submit" name="drop" value="<?php echo lang('Drop'); ?> "<?php echo confirm(); ?> ><?php } if (support("partitioning")) { $partition_table = preg_match('~RANGE|LIST~', $row["partition_by"]); print_fieldset("partition", lang('Partition by'), $row["partition_by"]); ?> <p> <?php echo "<select name='partition_by' onchange='partitionByChange(this);'" . on_help("getTarget(event).value.replace(/./, 'PARTITION BY \$&')", 1) . ">" . optionlist(array("" => "") + $partition_by, $row["partition_by"]) . "</select>"; ?> (<input name="partition" value="<?php echo h($row["partition"]); ?> ">) <?php echo lang('Partitions'); ?> : <input type="number" name="partitions" class="size<?php echo $partition_table || !$row["partition_by"] ? " hidden" : ""; ?> " value="<?php echo h($row["partitions"]); ?> ">
/** Print table columns for type edit * @param string * @param array * @param array * @param array returned by referencable_primary() * @return null */ function edit_type($key, $field, $collations, $foreign_keys = array()) { global $structured_types, $types, $unsigned, $on_actions; $type = $field["type"]; ?> <td><select name="<?php echo h($key); ?> [type]" class="type" onfocus="lastType = selectValue(this);" onchange="editingTypeChange(this);"<?php echo on_help("getTarget(event).value", 1); ?> ><?php if ($type && !isset($types[$type]) && !isset($foreign_keys[$type])) { array_unshift($structured_types, $type); } if ($foreign_keys) { $structured_types[lang('Foreign keys')] = $foreign_keys; } echo optionlist($structured_types, $type); ?> </select> <td><input name="<?php echo h($key); ?> [length]" value="<?php echo h($field["length"]); ?> " size="3" onfocus="editingLengthFocus(this);"<?php echo !$field["length"] && preg_match('~var(char|binary)$~', $type) ? " class='required'" : ""; ?> onchange="editingLengthChange(this);" onkeyup="this.onchange();"><td class="options"><?php //! type="number" with enabled JavaScript echo "<select name='" . h($key) . "[collation]'" . (preg_match('~(char|text|enum|set)$~', $type) ? "" : " class='hidden'") . '><option value="">(' . lang('collation') . ')' . optionlist($collations, $field["collation"]) . '</select>'; echo $unsigned ? "<select name='" . h($key) . "[unsigned]'" . (!$type || preg_match('~((^|[^o])int|float|double|decimal)$~', $type) ? "" : " class='hidden'") . '><option>' . optionlist($unsigned, $field["unsigned"]) . '</select>' : ''; echo isset($field['on_update']) ? "<select name='" . h($key) . "[on_update]'" . (preg_match('~timestamp|datetime~', $type) ? "" : " class='hidden'") . '>' . optionlist(array("" => "(" . lang('ON UPDATE') . ")", "CURRENT_TIMESTAMP"), $field["on_update"]) . '</select>' : ''; echo $foreign_keys ? "<select name='" . h($key) . "[on_delete]'" . (preg_match("~`~", $type) ? "" : " class='hidden'") . "><option value=''>(" . lang('ON DELETE') . ")" . optionlist(explode("|", $on_actions), $field["on_delete"]) . "</select> " : " "; // space for IE }
} $tables++; } echo support("comment") ? "<td id='Comment-" . h($name) . "'> " : ""; } echo "<tr><td> <th>" . lang('%d in total', count($tables_list)); echo "<td>" . nbsp($jush == "sql" ? $connection->result("SELECT @@storage_engine") : ""); echo "<td>" . nbsp(db_collation(DB, collations())); foreach (array("Data_length", "Index_length", "Data_free") as $key) { echo "<td align='right' id='sum-{$key}'> "; } echo "</table>\n"; if (!information_schema(DB)) { $vacuum = "<input type='submit' value='" . lang('Vacuum') . "'" . on_help("'VACUUM'") . "> "; $optimize = "<input type='submit' name='optimize' value='" . lang('Optimize') . "'" . on_help($jush == "sql" ? "'OPTIMIZE TABLE'" : "'VACUUM OPTIMIZE'") . "> "; echo "<fieldset><legend>" . lang('Selected') . " <span id='selected'></span></legend><div>" . ($jush == "sqlite" ? $vacuum : ($jush == "pgsql" ? $vacuum . $optimize : ($jush == "sql" ? "<input type='submit' value='" . lang('Analyze') . "'" . on_help("'ANALYZE TABLE'") . "> " . $optimize . "<input type='submit' name='check' value='" . lang('Check') . "'" . on_help("'CHECK TABLE'") . "> " . "<input type='submit' name='repair' value='" . lang('Repair') . "'" . on_help("'REPAIR TABLE'") . "> " : ""))) . "<input type='submit' name='truncate' value='" . lang('Truncate') . "'" . confirm() . on_help($jush == "sqlite" ? "'DELETE'" : "'TRUNCATE" . ($jush == "pgsql" ? "'" : " TABLE'")) . "> " . "<input type='submit' name='drop' value='" . lang('Drop') . "'" . confirm() . on_help("'DROP TABLE'") . ">\n"; $databases = support("scheme") ? $adminer->schemas() : $adminer->databases(); if (count($databases) != 1 && $jush != "sqlite") { $db = isset($_POST["target"]) ? $_POST["target"] : (support("scheme") ? $_GET["ns"] : DB); echo "<p>" . lang('Move to other database') . ": "; echo $databases ? html_select("target", $databases, $db) : '<input name="target" value="' . h($db) . '" autocapitalize="off">'; echo " <input type='submit' name='move' value='" . lang('Move') . "'>"; echo support("copy") ? " <input type='submit' name='copy' value='" . lang('Copy') . "'>" : ""; echo "\n"; } echo "<input type='hidden' name='all' value='' onclick=\"selectCount('selected', formChecked(this, /^(tables|views)\\[/));" . (support("table") ? " selectCount('selected2', formChecked(this, /^tables\\[/) || {$tables});" : "") . "\">\n"; // used by trCheck() echo "<input type='hidden' name='token' value='{$token}'>\n"; echo "</div></fieldset>\n"; } echo "</form>\n";