mirror of
https://github.com/vrana/adminer.git
synced 2025-08-17 20:01:25 +02:00
Use radio in export
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1160 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
@@ -430,6 +430,30 @@ class Adminer {
|
||||
return $return;
|
||||
}
|
||||
|
||||
/** Returns export output options
|
||||
* @param bool generate select (otherwise radio)
|
||||
* @return string
|
||||
*/
|
||||
function dumpOutput($select) {
|
||||
$return = array('text' => lang('open'), 'file' => lang('save'));
|
||||
if (function_exists('gzencode')) {
|
||||
$return['gz'] = 'gzip';
|
||||
}
|
||||
if (function_exists('bzcompress')) {
|
||||
$return['bz2'] = 'bzip2';
|
||||
}
|
||||
// ZipArchive requires temporary file, ZIP can be created by gzcompress - see PEAR File_Archive
|
||||
return html_select("output", $return, "text", $select);
|
||||
}
|
||||
|
||||
/** Returns export format options
|
||||
* @param bool generate select (otherwise radio)
|
||||
* @return string
|
||||
*/
|
||||
function dumpFormat($select) {
|
||||
return html_select("format", array('sql' => 'SQL', 'csv' => 'CSV'), "sql", $select);
|
||||
}
|
||||
|
||||
/** Prints navigation after Adminer title
|
||||
* @param string can be "auth" if there is no database connection or "db" if there is no database selected
|
||||
* @return null
|
||||
|
@@ -115,7 +115,8 @@ DROP PROCEDURE adminer_alter;
|
||||
}
|
||||
|
||||
function dump_data($table, $style, $select = "") {
|
||||
global $connection, $max_packet;
|
||||
global $connection;
|
||||
$max_packet = 1048576; // default, minimum is 1024
|
||||
if ($style) {
|
||||
if ($_POST["format"] != "csv" && $style == "TRUNCATE+INSERT") {
|
||||
dump("TRUNCATE " . idf_escape($table) . ";\n");
|
||||
@@ -165,31 +166,18 @@ function dump_data($table, $style, $select = "") {
|
||||
}
|
||||
|
||||
function dump_headers($identifier, $multi_table = false) {
|
||||
$compress = $_POST["compress"];
|
||||
$filename = (strlen($identifier) ? friendly_url($identifier) : "dump");
|
||||
$output = $_POST["output"];
|
||||
$ext = ($_POST["format"] == "sql" ? "sql" : ($multi_table ? "tar" : "csv")); // multiple CSV packed to TAR
|
||||
header("Content-Type: " .
|
||||
($compress == "bz2" ? "application/x-bzip" :
|
||||
($compress == "gz" ? "application/x-gzip" :
|
||||
($output == "bz2" ? "application/x-bzip" :
|
||||
($output == "gz" ? "application/x-gzip" :
|
||||
($ext == "tar" ? "application/x-tar" :
|
||||
($ext == "sql" || $_POST["output"] != "file" ? "text/plain" : "text/csv") . "; charset=utf-8"
|
||||
($ext == "sql" || $output != "file" ? "text/plain" : "text/csv") . "; charset=utf-8"
|
||||
))));
|
||||
if ($_POST["output"] == "file" || $compress) {
|
||||
header("Content-Disposition: attachment; filename=$filename.$ext" . (ereg('[0-9a-z]', $compress) ? ".$compress" : ""));
|
||||
if ($output != "text") {
|
||||
header("Content-Disposition: attachment; filename=$filename.$ext" . ($output != "file" && !ereg('[^0-9a-z]', $output) ? ".$output" : ""));
|
||||
}
|
||||
session_write_close();
|
||||
return $ext;
|
||||
}
|
||||
|
||||
$compress = array();
|
||||
if (function_exists('gzencode')) {
|
||||
$compress['gz'] = 'gzip';
|
||||
}
|
||||
if (function_exists('bzcompress')) {
|
||||
$compress['bz2'] = 'bzip2';
|
||||
}
|
||||
// ZipArchive requires temporary file, ZIP can be created by gzcompress - see PEAR File_Archive
|
||||
$dump_output = "<select name='output'>" . optionlist(array('text' => lang('open'), 'file' => lang('save'))) . "</select>";
|
||||
$dump_format = "<select name='format'>" . optionlist(array('sql' => 'SQL', 'csv' => 'CSV')) . "</select>";
|
||||
$dump_compress = ($compress ? "<select name='compress'><option>" . optionlist($compress) . "</select>" : "");
|
||||
$max_packet = 1048576; // default, minimum is 1024
|
||||
|
@@ -74,6 +74,24 @@ function checkbox($name, $value, $checked, $label = "", $onclick = "") {
|
||||
return (strlen($label) ? "<label for='checkbox-$id'>$return" . h($label) . "</label>" : $return);
|
||||
}
|
||||
|
||||
/** Generate HTML radio list
|
||||
* @param string
|
||||
* @param array
|
||||
* @param string
|
||||
* @param bool generate select (otherwise radio)
|
||||
* @return string
|
||||
*/
|
||||
function html_select($name, $options, $value, $select = true) {
|
||||
if ($select) {
|
||||
return "<select name='" . h($name) . "'>" . optionlist($options, $value) . "</select>";
|
||||
}
|
||||
$return = "";
|
||||
foreach ($options as $key => $val) {
|
||||
$return .= "<label><input type='radio' name='" . h($name) . "' value='" . h($key) . "'" . ($key == $value ? " checked" : "") . ">" . h($val) . "</label>";
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/** Generate list of HTML options
|
||||
* @param array array of strings or arrays (creates optgroup)
|
||||
* @param mixed
|
||||
@@ -457,10 +475,10 @@ function process_input($field) {
|
||||
*/
|
||||
function dump($string = null) { // null $string forces sending of buffer
|
||||
static $buffer = ""; // used to improve compression and to allow GZ archives unpackable in Total Commander
|
||||
if ($_POST["compress"]) {
|
||||
if (!ereg("text|file", $_POST["output"])) {
|
||||
$buffer .= $string;
|
||||
if (!isset($string) || strlen($buffer) > 1e6) {
|
||||
if ($_POST["compress"] == "bz2") {
|
||||
if ($_POST["output"] == "bz2") {
|
||||
echo bzcompress($buffer); // should not be called repeatedly but it would require whole buffer in memory or temporary file
|
||||
} else {
|
||||
echo gzencode($buffer);
|
||||
|
Reference in New Issue
Block a user