From 86a93514a7755c8941dd49432537f44d3f90621d Mon Sep 17 00:00:00 2001 From: jakubvrana Date: Sun, 31 May 2009 20:07:32 +0000 Subject: [PATCH] Relative date and time functions git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@633 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- changes.txt | 1 + include/editing.inc.php | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/changes.txt b/changes.txt index 6f57ba2c..6e10d813 100644 --- a/changes.txt +++ b/changes.txt @@ -1,6 +1,7 @@ phpMinAdmin 1.11.0: Connection through socket by server :/path/to/socket Display execution time in SQL query +Relative date and time functions Version checker Separate JavaScript functions Always use the default style before the external one diff --git a/include/editing.inc.php b/include/editing.inc.php index d71228f3..61bafca6 100644 --- a/include/editing.inc.php +++ b/include/editing.inc.php @@ -25,14 +25,24 @@ function input($name, $field, $value, $separator = "") { //! pass empty if (preg_match('~char|date|time~', $field["type"])) { $options = (preg_match('~char~', $field["type"]) ? array("", "md5", "sha1", "password", "uuid") : array("", "now")); } - if (!isset($_GET["clone"]) && !isset($_GET["call"]) && preg_match('~int|float|double|decimal~', $field["type"])) { - $options = array("", "+", "-"); + if (!isset($_GET["clone"]) && !isset($_GET["call"])) { + if (preg_match('~int|float|double|decimal~', $field["type"])) { + $options = array("", "+", "-"); + } + if (preg_match('~date~', $field["type"])) { + $options[] = "+ interval"; + $options[] = "- interval"; + } + if (preg_match('~time~', $field["type"])) { + $options[] = "addtime"; + $options[] = "subtime"; + } } } if ($field["null"] || isset($_GET["default"])) { array_unshift($options, "NULL"); } - echo (count($options) > 1 || isset($_GET["select"]) ? '' : "") . $separator; + echo (count($options) > 1 || isset($_GET["select"]) ? '' : "") . $separator; if ($field["type"] == "set") { //! 64 bits preg_match_all("~'((?:[^']+|'')*)'~", $field["length"], $matches); foreach ($matches[1] as $i => $val) { @@ -74,8 +84,12 @@ function process_input($name, $field) { return $value; } elseif (preg_match('~^(now|uuid)$~', $function)) { return "$function()"; - } elseif (preg_match('~^(\\+|-)$~', $function)) { + } elseif (preg_match('~^[+-]$~', $function)) { return idf_escape($name) . " $function '" . $dbh->escape_string($value) . "'"; + } elseif (preg_match('~^[+-] interval$~', $function)) { + return idf_escape($name) . " $function " . (preg_match("~^([0-9]+|'[0-9.: -]') [A-Z_]+$~i", $value) ? $value : "'" . $dbh->escape_string($value) . "'") . ""; + } elseif (preg_match('~^(addtime|subtime)$~', $function)) { + return "$function(" . idf_escape($name) . ", '" . $dbh->escape_string($value) . "')"; } elseif (preg_match('~^(md5|sha1|password)$~', $function)) { return "$function('" . $dbh->escape_string($value) . "')"; } else {