Date localization

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@917 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana 2009-07-27 16:32:56 +00:00
parent f93c84e4d8
commit a0def4790e
17 changed files with 50 additions and 25 deletions

View file

@ -17,7 +17,7 @@ if (!$error && $_POST) {
$call = array(); $call = array();
foreach ($routine["fields"] as $key => $field) { foreach ($routine["fields"] as $key => $field) {
if (in_array($key, $in)) { if (in_array($key, $in)) {
$val = process_input($key, $field); $val = process_input($field);
if ($val === false) { if ($val === false) {
$val = "''"; $val = "''";
} }

View file

@ -11,7 +11,7 @@ if ($_POST && !$error && !isset($_GET["select"])) {
$location = ($_POST["insert"] ? $_SERVER["REQUEST_URI"] : $SELF . (isset($_GET["default"]) ? "table=" : "select=") . urlencode($_GET["edit"])); // "insert" to continue edit or insert $location = ($_POST["insert"] ? $_SERVER["REQUEST_URI"] : $SELF . (isset($_GET["default"]) ? "table=" : "select=") . urlencode($_GET["edit"])); // "insert" to continue edit or insert
$set = array(); $set = array();
foreach ($fields as $name => $field) { foreach ($fields as $name => $field) {
$val = process_input($name, $field); $val = process_input($field);
if (!isset($_GET["default"])) { if (!isset($_GET["default"])) {
if ($val !== false || !$update) { if ($val !== false || !$update) {
$set[] = "\n" . idf_escape($name) . " = " . ($val !== false ? $val : "''"); $set[] = "\n" . idf_escape($name) . " = " . ($val !== false ? $val : "''");
@ -74,6 +74,9 @@ if ($fields) {
? (strlen($row[$name]) && ($field["type"] == "enum" || $field["type"] == "set") ? intval($row[$name]) : $row[$name]) ? (strlen($row[$name]) && ($field["type"] == "enum" || $field["type"] == "set") ? intval($row[$name]) : $row[$name])
: ($_POST["clone"] && $field["auto_increment"] ? "" : (isset($_GET["select"]) ? false : $field["default"])) : ($_POST["clone"] && $field["auto_increment"] ? "" : (isset($_GET["select"]) ? false : $field["default"]))
); );
if (!$_POST["save"] && is_string($value)) {
$value = $adminer->editVal($value, $field);
}
$function = ($_POST["save"] ? (string) $_POST["function"][$name] : ($where && $field["on_update"] == "CURRENT_TIMESTAMP" ? "now" : ($value === false ? null : (isset($value) ? '' : 'NULL')))); $function = ($_POST["save"] ? (string) $_POST["function"][$name] : ($where && $field["on_update"] == "CURRENT_TIMESTAMP" ? "now" : ($value === false ? null : (isset($value) ? '' : 'NULL'))));
input($field, $value, $function); input($field, $value, $function);
if (isset($_GET["default"]) && $field["type"] == "timestamp") { if (isset($_GET["default"]) && $field["type"] == "timestamp") {

View file

@ -110,7 +110,7 @@ class Adminer {
} }
/** Value printed in select table /** Value printed in select table
* @param string escaped value to print * @param string HTML-escaped value to print
* @param string link to foreign key * @param string link to foreign key
* @param array single field returned from fields() * @param array single field returned from fields()
* @return string * @return string
@ -123,6 +123,15 @@ class Adminer {
return ($link ? "<a href=\"$link\">$return</a>" : $return); return ($link ? "<a href=\"$link\">$return</a>" : $return);
} }
/** Value conversion used in select and edit
* @param string
* @param array single field returned from fields()
* @return
*/
function editVal($val, $field) {
return $val;
}
/** Print columns box in select /** Print columns box in select
* @param array result of selectColumnsProcess() * @param array result of selectColumnsProcess()
* @param array selectable columns * @param array selectable columns
@ -263,7 +272,7 @@ class Adminer {
$return[] = "MATCH (" . idf_escape($val["col"]) . ") AGAINST (" . $dbh->quote($val["val"]) . " IN BOOLEAN MODE)"; $return[] = "MATCH (" . idf_escape($val["col"]) . ") AGAINST (" . $dbh->quote($val["val"]) . " IN BOOLEAN MODE)";
} else { } else {
$in = process_length($val["val"]); $in = process_length($val["val"]);
$cond = " $val[op]" . (ereg('NULL$', $val["op"]) ? "" : (ereg('IN$', $val["op"]) ? " (" . (strlen($in) ? $in : "NULL") . ")" : " " . $dbh->quote($val["val"]))); $cond = " $val[op]" . (ereg('NULL$', $val["op"]) ? "" : (ereg('IN$', $val["op"]) ? " (" . (strlen($in) ? $in : "NULL") . ")" : " " . $this->processInput($fields[$val["col"]], $val["val"])));
if (strlen($val["col"])) { if (strlen($val["col"])) {
$return[] = idf_escape($val["col"]) . $cond; $return[] = idf_escape($val["col"]) . $cond;
} else { } else {
@ -379,15 +388,14 @@ class Adminer {
} }
/** Process sent input /** Process sent input
* @param string field name
* @param array single field from fields() * @param array single field from fields()
* @param string
* @param string
* @return string expression to use in a query * @return string expression to use in a query
*/ */
function processInput($name, $field) { function processInput($field, $value, $function = "") {
global $dbh; global $dbh;
$idf = bracket_escape($name); $name = $field["field"];
$function = $_POST["function"][$idf];
$value = $_POST["fields"][$idf];
$return = $dbh->quote($value); $return = $dbh->quote($value);
if (ereg('^(now|uuid)$', $function)) { if (ereg('^(now|uuid)$', $function)) {
$return = "$function()"; $return = "$function()";

View file

@ -318,7 +318,7 @@ function input($field, $value, $function) {
} elseif (strpos($field["type"], "text") !== false) { } elseif (strpos($field["type"], "text") !== false) {
echo '<textarea name="fields[' . $name . ']" cols="50" rows="12"' . $onchange . '>' . htmlspecialchars($value) . '</textarea>'; echo '<textarea name="fields[' . $name . ']" cols="50" rows="12"' . $onchange . '>' . htmlspecialchars($value) . '</textarea>';
} elseif (ereg('binary|blob', $field["type"])) { } elseif (ereg('binary|blob', $field["type"])) {
echo (ini_get("file_uploads") ? '<input type="file" name="' . $name . '"' . $onchange . '>' : lang('File uploads are disabled.') . ' '); echo (ini_get("file_uploads") ? '<input type="file" name="' . $name . '"' . $onchange . '>' : lang('File uploads are disabled.'));
} else { } else {
// int(3) is only a display hint // int(3) is only a display hint
$maxlength = (!ereg('int', $field["type"]) && preg_match('~^([0-9]+)(,([0-9]+))?$~', $field["length"], $match) ? ($match[1] + ($match[3] ? 1 : 0) + ($match[2] && !$field["unsigned"] ? 1 : 0)) : ($types[$field["type"]] ? $types[$field["type"]] + ($field["unsigned"] ? 0 : 1) : 0)); $maxlength = (!ereg('int', $field["type"]) && preg_match('~^([0-9]+)(,([0-9]+))?$~', $field["length"], $match) ? ($match[1] + ($match[3] ? 1 : 0) + ($match[2] && !$field["unsigned"] ? 1 : 0)) : ($types[$field["type"]] ? $types[$field["type"]] + ($field["unsigned"] ? 0 : 1) : 0));
@ -327,9 +327,9 @@ function input($field, $value, $function) {
} }
} }
function process_input($name, $field) { function process_input($field) {
global $dbh, $adminer; global $dbh, $adminer;
$idf = bracket_escape($name); $idf = bracket_escape($field["field"]);
$function = $_POST["function"][$idf]; $function = $_POST["function"][$idf];
$value = $_POST["fields"][$idf]; $value = $_POST["fields"][$idf];
if ($field["type"] == "enum" ? $value == -1 : $function == "orig") { if ($field["type"] == "enum" ? $value == -1 : $function == "orig") {
@ -347,7 +347,7 @@ function process_input($name, $field) {
} }
return "_binary" . $dbh->quote($file); return "_binary" . $dbh->quote($file);
} else { } else {
return $adminer->processInput($name, $field); return $adminer->processInput($field, $value, $function);
} }
} }

View file

@ -211,6 +211,7 @@ $translations = array(
'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.', '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)', '(anywhere)' => '(kdekoliv)',
'%.3f s' => '%.3f s', '%.3f s' => '%.3f s',
'$1-$3-$5' => '$6.$4.$1',
'History' => 'Historie', 'History' => 'Historie',
'Variables' => 'Proměnné', 'Variables' => 'Proměnné',
'Source and target columns must have the same data type, there must be an index on the target columns and referenced data must exists.' => 'Zdrojové a cílové sloupce musí mít stejný datový typ, nad cílovými sloupci musí být definován index a odkazovaná data musí existovat.', 'Source and target columns must have the same data type, there must be an index on the target columns and referenced data must exists.' => 'Zdrojové a cílové sloupce musí mít stejný datový typ, nad cílovými sloupci musí být definován index a odkazovaná data musí existovat.',

View file

@ -211,6 +211,7 @@ $translations = array(
'Stop on error' => 'Bei Fehler anhaltan', 'Stop on error' => 'Bei Fehler anhaltan',
'Select table' => 'Tabelle auswählen', 'Select table' => 'Tabelle auswählen',
'%.3f s' => '%.3f s', '%.3f s' => '%.3f s',
'$1-$3-$5' => '$6.$4.$1',
'History' => 'History', 'History' => 'History',
'Variables' => 'Variablen', 'Variables' => 'Variablen',
'Source and target columns must have the same data type, there must be an index on the target columns and referenced data must exists.' => 'Spalten des Ursprungs und des Zieles müssen vom gleichen Datentyp sein, es muss unter den Zielspalten ein Index existieren und die referenzierten Daten müssen existieren.', 'Source and target columns must have the same data type, there must be an index on the target columns and referenced data must exists.' => 'Spalten des Ursprungs und des Zieles müssen vom gleichen Datentyp sein, es muss unter den Zielspalten ein Index existieren und die referenzierten Daten müssen existieren.',

View file

@ -211,6 +211,7 @@ $translations = array(
'Stop on error' => 'Parar en caso de error', 'Stop on error' => 'Parar en caso de error',
'Select table' => 'Seleccionar tabla', 'Select table' => 'Seleccionar tabla',
'%.3f s' => '%.3f s', '%.3f s' => '%.3f s',
'$1-$3-$5' => '$5/$3/$1',
'History' => 'History', 'History' => 'History',
'Variables' => 'Variables', 'Variables' => 'Variables',
'Source and target columns must have the same data type, there must be an index on the target columns and referenced data must exists.' => 'Las columnas de origen y destino deben ser del mismo tipo, debe existir un índice entre las columnas del destino y el registro referenciado debe existir.', 'Source and target columns must have the same data type, there must be an index on the target columns and referenced data must exists.' => 'Las columnas de origen y destino deben ser del mismo tipo, debe existir un índice entre las columnas del destino y el registro referenciado debe existir.',

View file

@ -211,6 +211,7 @@ $translations = array(
'Stop on error' => 'Peatuda vea esinemisel', 'Stop on error' => 'Peatuda vea esinemisel',
'Select table' => 'Vali tabel', 'Select table' => 'Vali tabel',
'%.3f s' => '%.3f s', '%.3f s' => '%.3f s',
'$1-$3-$5' => '$6.$4.$1',
'History' => 'Ajalugu', 'History' => 'Ajalugu',
'Variables' => 'Muutujad', 'Variables' => 'Muutujad',
'Source and target columns must have the same data type, there must be an index on the target columns and referenced data must exists.' => 'Lähte- ja sihtveerud peavad eksisteerima ja omama sama andmetüüpi, sihtveergudel peab olema määratud indeks ning viidatud andmed peavad eksisteerima.', 'Source and target columns must have the same data type, there must be an index on the target columns and referenced data must exists.' => 'Lähte- ja sihtveerud peavad eksisteerima ja omama sama andmetüüpi, sihtveergudel peab olema määratud indeks ning viidatud andmed peavad eksisteerima.',

View file

@ -211,6 +211,7 @@ $translations = array(
'Stop on error' => 'Arrêt sur erreur', 'Stop on error' => 'Arrêt sur erreur',
'Select table' => 'Selectionner la table', 'Select table' => 'Selectionner la table',
'%.3f s' => '%.3f s', '%.3f s' => '%.3f s',
'$1-$3-$5' => '$5/$3/$1',
'History' => 'Historique', 'History' => 'Historique',
'Variables' => 'Variables', 'Variables' => 'Variables',
'Source and target columns must have the same data type and there must be an index on the target columns.' => 'Les colonnes selectionnées et les colonnes de destination doivent être du même type et il doit y avoir un index sur les colonnes de destination.', 'Source and target columns must have the same data type and there must be an index on the target columns.' => 'Les colonnes selectionnées et les colonnes de destination doivent être du même type et il doit y avoir un index sur les colonnes de destination.',

View file

@ -211,6 +211,7 @@ $translations = array(
'Stop on error' => 'Stop su errore', 'Stop on error' => 'Stop su errore',
'Select table' => 'Scegli tabella', 'Select table' => 'Scegli tabella',
'%.3f s' => '%.3f s', '%.3f s' => '%.3f s',
'$1-$3-$5' => '$5/$3/$1',
'History' => 'Storico', 'History' => 'Storico',
'Variables' => 'Variabili', 'Variables' => 'Variabili',
'Source and target columns must have the same data type and there must be an index on the target columns.' => 'Le colonne sorgente e destinazione devono essere dello stesso tipo e ci deve essere un indice sulla colonna di destinazione.', 'Source and target columns must have the same data type and there must be an index on the target columns.' => 'Le colonne sorgente e destinazione devono essere dello stesso tipo e ci deve essere un indice sulla colonna di destinazione.',

View file

@ -211,6 +211,7 @@ $translations = array(
'Stop on error' => 'Stoppen bij fout', 'Stop on error' => 'Stoppen bij fout',
'Select table' => 'Selecteer tabel', 'Select table' => 'Selecteer tabel',
'%.3f s' => '%.3f s', '%.3f s' => '%.3f s',
'$1-$3-$5' => '$5-$3-$1',
'History' => 'Geschiedenis', 'History' => 'Geschiedenis',
'Variables' => 'Variabelen', 'Variables' => 'Variabelen',
'Source and target columns must have the same data type and there must be an index on the target columns.' => 'Bron- en doelkolommen moeten van hetzelfde data type zijn en er moet een index bestaan op de gekozen kolommen.', 'Source and target columns must have the same data type and there must be an index on the target columns.' => 'Bron- en doelkolommen moeten van hetzelfde data type zijn en er moet een index bestaan op de gekozen kolommen.',

View file

@ -211,6 +211,7 @@ $translations = array(
'Maximum number of allowed fields exceeded. Please increase %s and %s.' => 'Достигнуто максимальное значение количества доступных полей. Увеличьте %s и %s.', 'Maximum number of allowed fields exceeded. Please increase %s and %s.' => 'Достигнуто максимальное значение количества доступных полей. Увеличьте %s и %s.',
'(anywhere)' => '(в любом месте)', '(anywhere)' => '(в любом месте)',
'%.3f s' => '%.3f s', '%.3f s' => '%.3f s',
'$1-$3-$5' => '$5.$3.$1',
'History' => 'История', 'History' => 'История',
'Variables' => 'Переменные', 'Variables' => 'Переменные',
'Source and target columns must have the same data type, there must be an index on the target columns and referenced data must exists.' => 'Колонки должны иметь одинаковые типы данных, в результирующей колонке должен быть индекс, данные для импорта должны существовать.', 'Source and target columns must have the same data type, there must be an index on the target columns and referenced data must exists.' => 'Колонки должны иметь одинаковые типы данных, в результирующей колонке должен быть индекс, данные для импорта должны существовать.',

View file

@ -211,6 +211,7 @@ $translations = array(
'Maximum number of allowed fields exceeded. Please increase %s and %s.' => 'Bol prekročený maximálny počet povolených polí. Zvýšte prosím %s a %s.', 'Maximum number of allowed fields exceeded. Please increase %s and %s.' => 'Bol prekročený maximálny počet povolených polí. Zvýšte prosím %s a %s.',
'(anywhere)' => '(kdekoľvek)', '(anywhere)' => '(kdekoľvek)',
'%.3f s' => '%.3f s', '%.3f s' => '%.3f s',
'$1-$3-$5' => '$6.$4.$1',
'History' => 'História', 'History' => 'História',
'Variables' => 'Premenné', 'Variables' => 'Premenné',
'Source and target columns must have the same data type and there must be an index on the target columns.' => 'Zdrojové a cieľové stĺpce musia mať rovnaký dátový typ a nad cieľovými stĺpcami musí byť definovaný index.', 'Source and target columns must have the same data type and there must be an index on the target columns.' => 'Zdrojové a cieľové stĺpce musia mať rovnaký dátový typ a nad cieľovými stĺpcami musí byť definovaný index.',

View file

@ -211,6 +211,7 @@ $translations = array(
'Stop on error' => '出错时停止', 'Stop on error' => '出错时停止',
'Select table' => '选择表', 'Select table' => '选择表',
'%.3f s' => '%.3f 秒', '%.3f s' => '%.3f 秒',
'$1-$3-$5' => '$1.$3.$5',
'History' => '历史', 'History' => '历史',
'Variables' => '变量', 'Variables' => '变量',
'Source and target columns must have the same data type and there must be an index on the target columns.' => '源列和目标列必须具有相同的数据类型并且在目标列的必须是一个索引', 'Source and target columns must have the same data type and there must be an index on the target columns.' => '源列和目标列必须具有相同的数据类型并且在目标列的必须是一个索引',

View file

@ -67,7 +67,7 @@ if ($_POST && !$error) {
if (!$_POST["delete"]) { if (!$_POST["delete"]) {
$set = array(); $set = array();
foreach ($columns as $name => $val) { //! should check also for edit or insert privileges foreach ($columns as $name => $val) { //! should check also for edit or insert privileges
$val = process_input($name, $fields[$name]); $val = process_input($fields[$name]);
if ($_POST["clone"]) { if ($_POST["clone"]) {
$set[] = ($val !== false ? $val : idf_escape($name)); $set[] = ($val !== false ? $val : idf_escape($name));
} elseif ($val !== false) { } elseif ($val !== false) {
@ -201,6 +201,7 @@ if (!$columns) {
$email_fields[$key] = (is_email($val) ? $names[$key] : ""); //! filled e-mails may be contained on other pages $email_fields[$key] = (is_email($val) ? $names[$key] : ""); //! filled e-mails may be contained on other pages
} }
$link = ""; $link = "";
$val = $adminer->editVal($val, $fields[$key]);
if (!isset($val)) { if (!isset($val)) {
$val = "<i>NULL</i>"; $val = "<i>NULL</i>";
} else { } else {

View file

@ -118,6 +118,13 @@ ORDER BY ORDINAL_POSITION"); //! requires MySQL 5
return ($link ? "<a href=\"$link\">$return</a>" : $return); return ($link ? "<a href=\"$link\">$return</a>" : $return);
} }
function editVal($val, $field) {
if (ereg('date|timestamp', $field["type"])) {
return preg_replace('~^([0-9]{2}([0-9]+))-(0?([0-9]+))-(0?([0-9]+))~', lang('$1-$3-$5'), $val);
}
return $val;
}
function selectColumnsPrint($select, $columns) { function selectColumnsPrint($select, $columns) {
//! allow grouping functions by indexes //! allow grouping functions by indexes
} }
@ -177,11 +184,11 @@ ORDER BY ORDINAL_POSITION"); //! requires MySQL 5
} }
function selectSearchProcess($indexes, $fields) { function selectSearchProcess($indexes, $fields) {
global $dbh;
$return = array(); $return = array();
foreach ((array) $_GET["where"] as $val) { foreach ((array) $_GET["where"] as $val) {
if (strlen("$val[col]$val[val]")) { if (strlen("$val[col]$val[val]")) {
$cond = " = " . $dbh->quote($val["val"]); $value = $this->processInput($fields[$val["col"]], $val["val"]);
$cond = ($value == "NULL" ? " IS $value" : " = $value");
if (strlen($val["col"])) { if (strlen($val["col"])) {
$return[] = idf_escape($val["col"]) . $cond; $return[] = idf_escape($val["col"]) . $cond;
} else { } else {
@ -285,16 +292,9 @@ ORDER BY ORDINAL_POSITION"); //! requires MySQL 5
return $return; return $return;
} }
/** Process sent input function processInput($field, $value, $function = "") {
* @param string field name
* @param array single field from fields()
* @return string expression to use in a query
*/
function processInput($name, $field) {
global $dbh; global $dbh;
$idf = bracket_escape($name); $return = $dbh->quote(ereg('date|timestamp', $field["type"]) ? preg_replace_callback('(' . preg_replace('~(\\\\\\$([0-9]))~', '(?P<p\\2>[0-9]+)', preg_quote(lang('$1-$3-$5'))) . ')', 'conversion_date', $value) : $value);
$value = $_POST["fields"][$idf];
$return = $dbh->quote($value);
if (!ereg('varchar|text', $field["type"]) && !strlen($value)) { if (!ereg('varchar|text', $field["type"]) && !strlen($value)) {
$return = "NULL"; $return = "NULL";
} elseif (ereg('date|time', $field["type"]) && $value == "CURRENT_TIMESTAMP") { } elseif (ereg('date|time', $field["type"]) && $value == "CURRENT_TIMESTAMP") {

View file

@ -1 +1,4 @@
<?php <?php
function conversion_date($match) {
return ($match["p1"] ? $match["p1"] : ($match["p2"] < 70 ? 20 : 19) . $match["p2"]) . "-$match[p3]$match[p4]-$match[p5]$match[p6]";
}