]> git.joonet.de Git - adminer.git/commitdiff
Treat tinyint(1) as boolean
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Tue, 28 Jul 2009 10:09:05 +0000 (10:09 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Tue, 28 Jul 2009 10:09:05 +0000 (10:09 +0000)
Use $SELF and ENT_QUOTES for compiled images

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@922 7c3ca157-0c34-0410-bff1-cbf682f78f5c

adminer/include/adminer.inc.php
adminer/include/editing.inc.php
adminer/include/functions.inc.php
changes.txt
compile.php
editor/include/adminer.inc.php
todo.txt

index 9db9808aa1718db05868c376c5ab16dec21957a6..e07afd73909720e84be1e48fe4499511af689116 100644 (file)
@@ -382,10 +382,12 @@ class Adminer {
        /** Get options to display edit field
        * @param string table name
        * @param array single field from fields()
-       * @return array options for <select> or empty to display <input>
+       * @param string attributes to use inside the tag
+       * @param string
+       * @return string custom input field or empty string for default
        */
-       function editInput($table, $field) {
-               return false;
+       function editInput($table, $field, $attrs, $value) {
+               return '';
        }
        
        /** Process sent input
index 9202a43e831a02b86f397afb0511aac3edf29062..0c15ca607891df826b2870fe316543d0b49caec1 100644 (file)
@@ -56,7 +56,7 @@ function type_class($type) {
 }
 
 function edit_fields($fields, $collations, $type = "TABLE", $allowed = 0, $foreign_keys = array()) {
-       global $inout;
+       global $inout, $SELF; // $SELF is used by compiled images
        $column_comments = false;
        foreach ($fields as $field) {
                if (strlen($field["comment"])) {
index 547284ccffbc9fd258c62c4d982e6d0bd967462f..2b92a8209c5f813e3661e8d7568c5b0ac72d7716 100644 (file)
@@ -305,9 +305,9 @@ function input($field, $value, $function) {
                $first = array_search("", $functions);
                $onchange = ($first ? ' onchange="var f = this.form[\'function[' . addcslashes($name, "\r\n'\\") . ']\']; if (' . $first . ' > f.selectedIndex) f.selectedIndex = ' . $first . ';"' : '');
                echo (count($functions) > 1 ? '<select name="function[' . $name . ']">' . optionlist($functions, $function) . '</select>' : "&nbsp;") . '<td>';
-               $options = $adminer->editInput($_GET["edit"], $field); // usage in call is without a table
-               if (is_array($options)) {
-                       echo '<select name="fields[' . $name . ']"' . $onchange . '>' . optionlist(($options ? $options : array("" => "")), $value, true) . '</select>';
+               $input = $adminer->editInput($_GET["edit"], $field, ' name="fields[' . $name . ']"' . $onchange, $value); // usage in call is without a table
+               if (strlen($input)) {
+                       echo $input;
                } elseif ($field["type"] == "set") { //! 64 bits
                        preg_match_all("~'((?:[^']+|'')*)'~", $field["length"], $matches);
                        foreach ($matches[1] as $i => $val) {
index 0f75f025329e0a05970fe3a016eab39cee15377c..414646c6d6e0f341ac306f6e6b847a9492508041 100644 (file)
@@ -14,6 +14,7 @@ Remove Delete button from Edit page - use mass operation for it
 Faster multiple update, clone and delete
 Faster table list in navigation
 Use HTML Strict instead of XHTML
+Remove function minification for performance and customization
 Fix grant ALL PRIVILEGES with GRANT OPTION
 Fix CSV import
 Fix work with default values (thanks to Jiri Pospisil)
index bc1681d76071bafa086e9c44a7b10cd9145e61a6..e4b30622d18ff91e7c80d793eeedf11a526eea54 100644 (file)
@@ -177,8 +177,8 @@ if ($_COOKIE["adminer_lang"]) {
 }
 $file = str_replace('<script type="text/javascript" src="editing.js"></script>' . "\n", "", $file);
 $file = preg_replace_callback("~compile_file\\('([^']+)', '([^']+)'\\);~", 'compile_file', $file); // integrate static files
-$replace = 'htmlspecialchars(preg_replace("~\\\\\\\\?.*~", "", $_SERVER["REQUEST_URI"])) . "?file=\\1&amp;version=' . $VERSION;
-$file = preg_replace('~(?:\\.\\./adminer/|\\./)(default\\.css|functions\\.js|favicon\\.ico)~', '<?php echo ' . $replace . '"; ?>', $file);
+$replace = 'htmlspecialchars(preg_replace("~\\\\\\\\?.*~", "", $SELF), ENT_QUOTES) . "?file=\\1&amp;version=' . $VERSION;
+$file = preg_replace('~\\.\\./adminer/(default\\.css|functions\\.js|favicon\\.ico)~', '<?php echo ' . $replace . '"; ?>', $file);
 $file = preg_replace('~\\.\\./adminer/((plus|cross|up|down|arrow)\\.gif)~', '" . ' . $replace, $file);
 $file = str_replace("../externals/jush/", "http://jush.sourceforge.net/", $file);
 $file = preg_replace("~<\\?php\\s*\\?>\n?|\\?>\n?<\\?php~", '', $file);
index a8432306f9a6ab1f39a24fa2c808531e0af9575d..bb968cd949912b12a9fa01d65b6f598a0d9c820c 100644 (file)
@@ -108,6 +108,7 @@ ORDER BY ORDINAL_POSITION"); //! requires MySQL 5
        }
        
        function selectVal($val, $link, $field) {
+               global $SELF; // used by compiled images
                $return = ($val == "<i>NULL</i>" ? "&nbsp;" : $val);
                if (ereg('blob|binary', $field["type"]) && !is_utf8($val)) {
                        $return = lang('%d byte(s)', strlen($val));
@@ -115,6 +116,9 @@ ORDER BY ORDINAL_POSITION"); //! requires MySQL 5
                                $return = "<img src=\"$link\" alt='$return'>";
                        }
                }
+               if ($field["full_type"] == "tinyint(1)" && $return != "&nbsp;") { // bool
+                       $return = '<img src="' . ($val ? "../adminer/plus.gif" : "../adminer/cross.gif") . '" alt="' . htmlspecialchars($val) . '">';
+               }
                return ($link ? "<a href=\"$link\">$return</a>" : $return);
        }
        
@@ -268,34 +272,37 @@ ORDER BY ORDINAL_POSITION"); //! requires MySQL 5
                return (isset($_GET["select"]) ? array("orig" => lang('original')) : array()) + array("");
        }
        
-       function editInput($table, $field) {
+       function editInput($table, $field, $attrs, $value) {
                global $dbh;
-               $return = null;
                $foreign_keys = column_foreign_keys($table);
                foreach ((array) $foreign_keys[$field["field"]] as $foreign_key) {
                        if (count($foreign_key["source"]) == 1) {
                                $id = idf_escape($foreign_key["target"][0]);
                                $name = $this->rowDescription($foreign_key["table"]);
                                if (strlen($name) && $dbh->result($dbh->query("SELECT COUNT(*) FROM " . idf_escape($foreign_key["table"]))) <= 1000) { // optionlist with more than 1000 options would be too big
-                                       if ($field["null"]) {
+                                       $return = array();
+                                       $result = $dbh->query("SELECT $id, $name FROM " . idf_escape($foreign_key["table"]) . " ORDER BY 2");
+                                       if ($field["null"] || !$result->num_rows) { // empty <select> is not HTML-valid
                                                $return[""] = "";
                                        }
-                                       $result = $dbh->query("SELECT $id, $name FROM " . idf_escape($foreign_key["table"]) . " ORDER BY 2");
                                        while ($row = $result->fetch_row()) {
                                                $return[$row[0]] = $row[1];
                                        }
                                        $result->free();
-                                       break;
+                                       return "<select$attrs>" . optionlist($return, $value, true) . "</select>";
                                }
                        }
                }
-               return $return;
+               if ($field["full_type"] == "tinyint(1)") { // bool
+                       return '<input type="checkbox" value="' . htmlspecialchars($value ? $value : 1) . '"' . ($value ? ' checked="checked"' : '') . "$attrs>";
+               }
+               return '';
        }
        
        function processInput($field, $value, $function = "") {
                global $dbh;
                $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);
-               if (!ereg('varchar|text', $field["type"]) && !strlen($value)) {
+               if (!ereg('varchar|text', $field["type"]) && $field["full_type"] != "tinyint(1)" && !strlen($value)) {
                        $return = "NULL";
                } elseif (ereg('date|time', $field["type"]) && $value == "CURRENT_TIMESTAMP") {
                        $return = $value;
index 7eee427c85d3a63d0a858cb747022ee48397cbfd..5fd53d7c6e420dbd70cb76ef8b620708ee7009c4 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -22,7 +22,6 @@ Download external files (version checker and JUSH) from trusted HTTPS if Adminer
 ? AJAX editing - select page has all data to display edit form
 
 Editor:
-JavaScript data validation
+JavaScript data validation - columns containing word email, url, md5, sha1, ...
 Joining tables - PRIMARY KEY (table, joining)
 Rank, Tree structure
-Treat tinyint(1) as bool