]> git.joonet.de Git - adminer.git/commitdiff
EnumOption plugin
authorJakub Vrana <jakub@vrana.cz>
Thu, 10 Feb 2011 17:16:10 +0000 (18:16 +0100)
committerJakub Vrana <jakub@vrana.cz>
Thu, 10 Feb 2011 17:16:10 +0000 (18:16 +0100)
adminer/plugin.php
plugins/enum-option.php [new file with mode: 0644]

index 679384ca0af51e2596ca1c4c4d72bf75da187134..e083dd72c9ec164a96115fd6a505ae983a5796a8 100644 (file)
@@ -22,6 +22,7 @@ function adminer_object() {
                new AdminerSlugify,
                new AdminerTranslation,
                new AdminerForeignSystem,
+               new AdminerEnumOption,
        ));
 }
 
diff --git a/plugins/enum-option.php b/plugins/enum-option.php
new file mode 100644 (file)
index 0000000..280ae5f
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+
+/** Use <select><option> for enum edit instead of <input type="radio">
+* @author Jakub Vrana, http://www.vrana.cz/
+* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
+* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
+*/
+class AdminerEnumOption {
+       
+       function editInput($table, $field, $attrs, $value) {
+               if ($field["type"] == "enum") {
+                       $options = array("" => array());
+                       $selected = $value;
+                       if (isset($_GET["select"])) {
+                               $options[""][-1] = lang('original');
+                       }
+                       if ($field["null"]) {
+                               $options[""][""] = "NULL";
+                               if (!isset($value) && !isset($_GET["select"])) {
+                                       $selected = "";
+                               }
+                       }
+                       $options[""][0] = lang('empty');
+                       preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches);
+                       foreach ($matches[1] as $i => $val) {
+                               $val = stripcslashes(str_replace("''", "'", $val));
+                               $options[$i + 1] = $val;
+                               if ($value === $val) {
+                                       $selected = $i + 1;
+                               }
+                       }
+                       return "<select$attrs>" . optionlist($options, (string) $selected, 1) . "</select>"; // 1 - use keys
+               }
+       }
+       
+}