* A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres.php,v 1.289 2006/08/13 15:31:13 xzilla Exp $
+ * $Id: Postgres.php,v 1.290 2006/08/18 21:02:41 xzilla Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
 
        // Help sub pages
        var $help_page;
+
+       // Predefined size types
+       var $predefined_size_types = array('abstime','aclitem','bigserial','boolean','bytea','cid','cidr','circle','date','float4','float8','gtsvector','inet','int2','int4','int8','macaddr','money','oid','path','polygon','refcursor','regclass','regoper','regoperator','regproc','regprocedure','regtype','reltime','serial','smgr','text','tid','tinterval','tsquery','tsvector','varbit','void','xid');
        
        /**
         * Constructor
 
        /**
         * List tables in a database
         *
-        * $Id: tables.php,v 1.81 2006/08/04 20:42:24 xzilla Exp $
+        * $Id: tables.php,v 1.82 2006/08/18 21:02:41 xzilla Exp $
         */
 
        // Include application functions
                                }
 
                                $types = $data->getTypes(true, false, true);
-       
+                               $types_for_js = array();
+
                                $misc->printTrail('schema');
                                $misc->printTitle($lang['strcreatetable'], 'pg.table.create');
                                $misc->printMsg($msg);
 
+                               echo "<script src=\"tables.js\" type=\"text/javascript\"></script>";
                                echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
 
                                // Output table header
                                        echo "\t<tr>\n\t\t<td>", $i + 1, ". </td>\n";
                                        echo "\t\t<td><input name=\"field[{$i}]\" size=\"16\" maxlength=\"{$data->_maxNameLen}\" value=\"",
                                                htmlspecialchars($_REQUEST['field'][$i]), "\" /></td>\n";
-                                       echo "\t\t<td>\n\t\t\t<select name=\"type[{$i}]\">\n";
+                                       echo "\t\t<td>\n\t\t\t<select name=\"type[{$i}]\" id=\"types{$i}\" onchange=\"checkLengths(this.options[this.selectedIndex].value,{$i});\">\n";
                                        // Output any "magic" types
                                        foreach ($data->extraTypes as $v) {
+                                               $types_for_js[strtolower($v)] = 1;
                                                echo "\t\t\t\t<option value=\"", htmlspecialchars($v), "\"",
                                                (isset($_REQUEST['type'][$i]) && $v == $_REQUEST['type'][$i]) ? ' selected="selected"' : '', ">",
                                                        $misc->printVal($v), "</option>\n";
                                        $types->moveFirst();
                                        while (!$types->EOF) {
                                                $typname = $types->f['typname'];
+                                               $types_for_js[$typname] = 1;
                                                echo "\t\t\t\t<option value=\"", htmlspecialchars($typname), "\"",
                                                (isset($_REQUEST['type'][$i]) && $typname == $_REQUEST['type'][$i]) ? ' selected="selected"' : '', ">",
                                                        $misc->printVal($typname), "</option>\n";
                                                $types->moveNext();
                                        }
-                                       echo "\t\t\t</select>\n\t\t</td>\n";
+                                       echo "\t\t\t</select>\n\t\t\n";
+                                       if($i==0) { // only define js types array once
+                                               $predefined_size_types = array_intersect($data->predefined_size_types,array_keys($types_for_js));
+                                               $escaped_predef_types = array(); // the JS escaped array elements
+                                               foreach($predefined_size_types as $value) {
+                                                       $escaped_predef_types[] = "'{$value}'";
+                                               }
+                                               echo "<script type=\"text/javascript\">predefined_lengths = new Array(". implode(",",$escaped_predef_types) .");</script>\n\t</td>";
+                                       }
                                        
                                        // Output array type selector
                                        echo "\t\t<td>\n\t\t\t<select name=\"array[{$i}]\">\n";
                                        echo "\t\t\t\t<option value=\"[]\"", (isset($_REQUEST['array'][$i]) && $_REQUEST['array'][$i] == '[]') ? ' selected="selected"' : '', ">[ ]</option>\n";
                                        echo "\t\t\t</select>\n\t\t</td>\n";
                                        
-                                       echo "\t\t<td><input name=\"length[{$i}]\" size=\"10\" value=\"", 
+                                       echo "\t\t<td><input name=\"length[{$i}]\" id=\"lengths{$i}\" size=\"10\" value=\"", 
                                                htmlspecialchars($_REQUEST['length'][$i]), "\" /></td>\n";
                                        echo "\t\t<td><input type=\"checkbox\" name=\"notnull[{$i}]\"", (isset($_REQUEST['notnull'][$i])) ? ' checked="checked"' : '', " /></td>\n";
                                        echo "\t\t<td align=\"center\"><input type=\"checkbox\" name=\"uniquekey[{$i}]\""
                                        echo "\t\t<td><input name=\"default[{$i}]\" size=\"20\" value=\"", 
                                                htmlspecialchars($_REQUEST['default'][$i]), "\" /></td>\n";
                                        echo "\t\t<td><input name=\"colcomment[{$i}]\" size=\"40\" value=\"", 
-                                               htmlspecialchars($_REQUEST['colcomment'][$i]), "\" /></td>\n\t</tr>\n";
+                                               htmlspecialchars($_REQUEST['colcomment'][$i]), "\" />
+                                               <script type=\"text/javascript\">checkLengths(document.getElementById('types{$i}').value,{$i});</script>
+                                               </td>\n\t</tr>\n";
                                }       
                                echo "</table>\n";
                                echo "<p><input type=\"hidden\" name=\"action\" value=\"create\" />\n";
                        }
                        echo "</p>\n";
                        echo "</form>\n";
-                       echo "<script>rEB(document.getElementById('no_ac').checked);</script>";
+                       echo "<script type=\"text/javascript\">rEB(document.getElementById('no_ac').checked);</script>";
                }
                else {
                        if (!isset($_POST['values'])) $_POST['values'] = array();
 
        /**
         * List tables in a database
         *
-        * $Id: tblproperties.php,v 1.71 2006/08/03 19:03:32 xzilla Exp $
+        * $Id: tblproperties.php,v 1.72 2006/08/18 21:02:41 xzilla Exp $
         */
 
        // Include application functions
 
                                // Fetch all available types
                                $types = $data->getTypes(true, false, true);
+                               $types_for_js = array();
 
                                $misc->printTrail('table');
                                $misc->printTitle($lang['straddcolumn'], 'pg.column.add');
                                $misc->printMsg($msg);
-
+                               echo "<script src=\"tables.js\" type=\"text/javascript\"></script>";
                                echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
 
                                // Output table header
 
                                echo "<tr><td><input name=\"field\" size=\"16\" maxlength=\"{$data->_maxNameLen}\" value=\"",
                                        htmlspecialchars($_POST['field']), "\" /></td>";
-                               echo "<td><select name=\"type\">\n";                            
+                               echo "<td><select name=\"type\" id=\"type\" onchange=\"checkLengths(document.getElementById('type').value,'');\">\n";                           
                                // Output any "magic" types.  This came in with the alter column type so we'll check that
                                if ($data->hasAlterColumnType()) {
                                        foreach ($data->extraTypes as $v) {
+                                               $types_for_js[strtolower($v)] = 1;
                                                echo "<option value=\"", htmlspecialchars($v), "\"",
                                                ($v == $_POST['type']) ? ' selected="selected"' : '', ">",
                                                        $misc->printVal($v), "</option>\n";
                                }
                                while (!$types->EOF) {
                                        $typname = $types->f['typname'];
+                                       $types_for_js[$typname] = 1;
                                        echo "<option value=\"", htmlspecialchars($typname), "\"", ($typname == $_POST['type']) ? ' selected="selected"' : '', ">",
                                                $misc->printVal($typname), "</option>\n";
                                        $types->moveNext();
                                echo "<td><select name=\"array\">\n";
                                echo "<option value=\"\"", ($_POST['array'] == '') ? ' selected="selected"' : '', "></option>\n";
                                echo "<option value=\"[]\"", ($_POST['array'] == '[]') ? ' selected="selected"' : '', ">[ ]</option>\n";
-                               echo "</select></td>\n";
+                               echo "</select>";
+                               $predefined_size_types = array_intersect($data->predefined_size_types,array_keys($types_for_js));
+                               $escaped_predef_types = array(); // the JS escaped array elements
+                               foreach($predefined_size_types as $value) {
+                                       $escaped_predef_types[] = "'{$value}'";
+                               }
+                               echo "\t</td>\n";
 
-                               echo "<td><input name=\"length\" size=\"8\" value=\"",
+                               echo "<td><input name=\"length\" id=\"lengths\" size=\"8\" value=\"",
                                        htmlspecialchars($_POST['length']), "\" /></td>";
                                // Support for adding column with not null and default
                                if ($data->hasAlterColumnType()) {                                      
                                echo "<p><input type=\"submit\" value=\"{$lang['stradd']}\" />\n";
                                echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
                                echo "</form>\n";
-
+                               echo "<script type=\"text/javascript\">predefined_lengths = new Array(". implode(",",$escaped_predef_types) .");checkLengths(document.getElementById('type').value,'');</script>\n";
                                break;
                        case 2:
                                global $data, $lang;
                                $misc->printTrail('column');
                                $misc->printTitle($lang['straltercolumn'], 'pg.column.alter'); 
                                $misc->printMsg($msg);
+                               echo "<script src=\"tables.js\" type=\"text/javascript\"></script>";
 
                                echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
 
                                // Output table header
-                               echo "<table>\n<tr>";
+                               echo "<table>\n";
                                echo "<tr><th class=\"data required\">{$lang['strname']}</th>";
                                if ($data->hasAlterColumnType()) {
                                        echo "<th class=\"data required\" colspan=\"2\">{$lang['strtype']}</th>";
                                if ($data->hasAlterColumnType()) {
                                        // Fetch all available types
                                        $types = $data->getTypes(true, false, true);
+                                       $types_for_js = array();
                                        
-                                       echo "<td><select name=\"type\">\n";                            
+                                       echo "<td><select name=\"type\" id=\"type\" onchange=\"checkLengths(document.getElementById('type').value,'');\">\n";
                                        // Output any "magic" types.  This came in with Alter Column Type so we don't need to check that
                                        foreach ($data->extraTypes as $v) {
+                                               $types_for_js[strtolower($v)] = 1;
                                                echo "<option value=\"", htmlspecialchars($v), "\"",
                                                ($v == $_REQUEST['type']) ? ' selected="selected"' : '', ">",
                                                        $misc->printVal($v), "</option>\n";
                                        }
                                        while (!$types->EOF) {
                                                $typname = $types->f['typname'];
+                                               $types_for_js[$typname] = 1;
                                                echo "<option value=\"", htmlspecialchars($typname), "\"", ($typname == $_REQUEST['type']) ? ' selected="selected"' : '', ">",
                                                        $misc->printVal($typname), "</option>\n";
                                                $types->moveNext();
                                        echo "<td><select name=\"array\">\n";
                                        echo "<option value=\"\"", ($_REQUEST['array'] == '') ? ' selected="selected"' : '', "></option>\n";
                                        echo "<option value=\"[]\"", ($_REQUEST['array'] == '[]') ? ' selected="selected"' : '', ">[ ]</option>\n";
-                                       echo "</select></td>\n";
-       
-                                       echo "<td><input name=\"length\" size=\"8\" value=\"",
+                                       echo "</select>";
+                                       $predefined_size_types = array_intersect($data->predefined_size_types,array_keys($types_for_js));
+                                       $escaped_predef_types = array(); // the JS escaped array elements
+                                       foreach($predefined_size_types as $value) {
+                                               $escaped_predef_types[] = "'{$value}'";
+                                       }
+                                       echo "\t</td>\n";
+
+                                       echo "<td><input name=\"length\" id=\"lengths\" size=\"8\" value=\"",   
                                                htmlspecialchars($_REQUEST['length']), "\" /></td>";
                                } else {
                                        // Otherwise draw the read-only type name
                                echo "<input type=\"submit\" value=\"{$lang['stralter']}\" />\n";
                                echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
                                echo "</form>\n";
+                               echo "<script type=\"text/javascript\">predefined_lengths = new Array(". implode(",",$escaped_predef_types) .");checkLengths(document.getElementById('type').value,'');</script>\n";
                                                                
                                break;
                        case 2: