diff --git a/export.inc.php b/export.inc.php index 54877caf..7027046c 100644 --- a/export.inc.php +++ b/export.inc.php @@ -1,7 +1,7 @@ $val) { - if (preg_match("~[\"\n,]~", $val)) { + if (preg_match("~[\"\n,]~", $val) || (isset($val) && !strlen($val))) { $row[$key] = '"' . str_replace('"', '""', $val) . '"'; } } diff --git a/lang/cs.inc.php b/lang/cs.inc.php index a5915774..7c97aaf2 100644 --- a/lang/cs.inc.php +++ b/lang/cs.inc.php @@ -216,5 +216,4 @@ $translations = array( 'Stop on error' => 'Zastavit při chybě', 'Maximum number of allowed fields exceeded. Please increase %s and %s.' => 'Byl překročen maximální povolený počet polí. Zvyšte prosím %s a %s.', '(anywhere)' => '(kdekoliv)', - 'Export selected' => 'Export označených', ); diff --git a/select.inc.php b/select.inc.php index 9955d20a..938e7fb1 100644 --- a/select.inc.php +++ b/select.inc.php @@ -70,29 +70,34 @@ if ($_POST && !$error) { if ($_POST["export"]) { dump_headers($_GET["select"]); dump_table($_GET["select"], ""); - if ($_POST["all"]) { - dump_data($_GET["select"], "INSERT", ($where ? "FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", $where) : "")); - } else { - foreach ((array) $_POST["check"] as $val) { + if (is_array($_POST["check"])) { + foreach ($_POST["check"] as $val) { parse_str($val, $check); dump_data($_GET["select"], "INSERT", "FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", where($check)) . " LIMIT 1"); } + } else { + dump_data($_GET["select"], "INSERT", ($where ? "FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", $where) : "")); } exit; } if ($_POST["import"]) { $file = preg_replace("~^\xEF\xBB\xBF~", '', get_file("csv_file")); //! character set + $cols = ""; $rows = array(); //! packet size preg_match_all('~("[^"]*"|[^"\\n]+)+~', $file, $matches); - foreach ($matches[0] as $val) { + foreach ($matches[0] as $key => $val) { $row = array(); - preg_match_all('~(("[^"]*")+|[^,]*),~', "$val,", $fields); - foreach ($fields[1] as $field) { - $row[] = "'" . $mysql->escape_string(str_replace('""', '"', preg_replace('~".*"~s', '', $field))) . "'"; //! NULL + preg_match_all('~(("[^"]*")+|[^,]*),~', "$val,", $matches2); + if (!$key && !array_diff($matches2[1], array_keys($fields))) { //! doesn't work with column names containing ",\n + $cols = " (" . implode(", ", array_map('idf_escape', $matches2[1])) . ")"; + } else { + foreach ($matches2[1] as $col) { + $row[] = (!strlen($col) ? "NULL" : "'" . $mysql->escape_string(str_replace('""', '"', preg_replace('~^".*"$~s', '', $col))) . "'"); + } + $rows[] = "(" . implode(", ", $row) . ")"; } - $rows[] = "(" . implode(", ", $row) . ")"; } - $result = queries("INSERT INTO " . idf_escape($_GET["select"]) . " VALUES " . implode(", ", $rows)); + $result = queries("INSERT INTO " . idf_escape($_GET["select"]) . "$cols VALUES " . implode(", ", $rows)); query_redirect(queries(), remove_from_uri("page"), lang('%d row(s) has been imported.', $mysql->affected_rows), $result, false, !$result); } else { $result = true; @@ -325,7 +330,7 @@ for (var i=0; > i; i++) { echo " (" . lang('%d row(s)', $found_rows) . ")

\n"; echo ($_GET["db"] != "information_schema" ? "
" . lang('Edit') . "
\n" : ""); - echo "
" . lang('Export selected') . "
$dump_options
\n"; + echo "
" . lang('Export') . "
$dump_options
\n"; } $result->free(); echo "
" . lang('CSV Import') . "
\n";