Add a check in addForeignKey(). Other fixes.
authorsoranzo <soranzo>
Mon, 30 Aug 2004 10:15:48 +0000 (10:15 +0000)
committersoranzo <soranzo>
Mon, 30 Aug 2004 10:15:48 +0000 (10:15 +0000)
constraints.php

index 07dec87f761e339751ba3c80c253530bf664307a..0afd9cf5a5840e4769103f552e101e8cc027fc92 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List constraints on a table
         *
-        * $Id: constraints.php,v 1.36 2004/08/04 02:37:42 chriskl Exp $
+        * $Id: constraints.php,v 1.37 2004/08/30 10:15:48 soranzo Exp $
         */
 
        // Include application functions
 
                switch ($stage) {
                        case 2:
-                       
-                               // Copy the IndexColumnList variable from stage 2
-                               if (isset($_REQUEST['IndexColumnList']) && !isset($_REQUEST['SourceColumnList']))
-                                       $_REQUEST['SourceColumnList'] = serialize($_REQUEST['IndexColumnList']);
-                               
-                               // Initialise variables
-                               if (!isset($_POST['upd_action'])) $_POST['upd_action'] = null;
-                               if (!isset($_POST['del_action'])) $_POST['del_action'] = null;
-                               if (!isset($_POST['match'])) $_POST['match'] = null;
-                               if (!isset($_POST['deferrable'])) $_POST['deferrable'] = null;
-                               if (!isset($_POST['initially'])) $_POST['initially'] = null;
-                               $_REQUEST['target'] = unserialize($_REQUEST['target']);
-                               
-                               echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strtables']}: ",
-                                       $misc->printVal($_REQUEST['table']), ": {$lang['straddfk']}</h2>\n";
-                               $misc->printMsg($msg);
-
-                               // Unserialize target and fetch appropriate table.  This is a bit messy
-                               // because the table could be in another schema.
-                               if ($data->hasSchemas()) {
-                                       $data->setSchema($_REQUEST['target']['schemaname']);
-                               }
-                               $attrs = &$data->getTableAttributes($_REQUEST['target']['tablename']);
-                               if ($data->hasSchemas()) {
-                                       $data->setSchema($_REQUEST['schema']);
-                               }
-
-                               $selColumns = new XHTML_select('TableColumnList', true, 10);
-                               $selColumns->set_style('width: 10em;');
-
-                               if ($attrs->recordCount() > 0) {
-                                       while (!$attrs->EOF) {
-                                               $selColumns->add(new XHTML_Option($attrs->f['attname']));
-                                               $attrs->moveNext();
+                               // Check that they've given at least one source column
+                               if (!isset($_REQUEST['SourceColumnList']) && (!isset($_POST['IndexColumnList']) || !is_array($_POST['IndexColumnList']) || sizeof($_POST['IndexColumnList']) == 0))
+                                       addForeignKey(1, $lang['strfkneedscols']);
+                               else {
+                                       // Copy the IndexColumnList variable from stage 1
+                                       if (isset($_REQUEST['IndexColumnList']) && !isset($_REQUEST['SourceColumnList']))
+                                               $_REQUEST['SourceColumnList'] = serialize($_REQUEST['IndexColumnList']);
+                                       
+                                       // Initialise variables
+                                       if (!isset($_POST['upd_action'])) $_POST['upd_action'] = null;
+                                       if (!isset($_POST['del_action'])) $_POST['del_action'] = null;
+                                       if (!isset($_POST['match'])) $_POST['match'] = null;
+                                       if (!isset($_POST['deferrable'])) $_POST['deferrable'] = null;
+                                       if (!isset($_POST['initially'])) $_POST['initially'] = null;
+                                       $_REQUEST['target'] = unserialize($_REQUEST['target']);
+                                       
+                                       echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strtables']}: ",
+                                               $misc->printVal($_REQUEST['table']), ": {$lang['straddfk']}</h2>\n";
+                                       $misc->printMsg($msg);
+
+                                       // Unserialize target and fetch appropriate table. This is a bit messy
+                                       // because the table could be in another schema.
+                                       if ($data->hasSchemas())
+                                               $data->setSchema($_REQUEST['target']['schemaname']);
+                                       $attrs = &$data->getTableAttributes($_REQUEST['target']['tablename']);
+                                       if ($data->hasSchemas())
+                                               $data->setSchema($_REQUEST['schema']);
+
+                                       $selColumns = new XHTML_select('TableColumnList', true, 10);
+                                       $selColumns->set_style('width: 10em;');
+
+                                       if ($attrs->recordCount() > 0) {
+                                               while (!$attrs->EOF) {
+                                                       $selColumns->add(new XHTML_Option($attrs->f['attname']));
+                                                       $attrs->moveNext();
+                                               }
                                        }
-                               }
-
-                               $selIndex = new XHTML_select('IndexColumnList[]', true, 10);
-                               $selIndex->set_style('width: 10em;');
-                               $selIndex->set_attribute('id', 'IndexColumnList');
-                               $buttonAdd = new XHTML_Button('add', '>>');
-                               $buttonAdd->set_attribute('onclick', 'buttonPressed(this);');
-                               $buttonAdd->set_attribute('type', 'button');
 
-                               $buttonRemove = new XHTML_Button('remove', '<<');
-                               $buttonRemove->set_attribute('onclick', 'buttonPressed(this);');
-                               $buttonRemove->set_attribute('type', 'button');
-
-                               echo "<form onsubmit=\"doSelectAll();\" name=\"formIndex\" action=\"$PHP_SELF\" method=\"post\">\n";    
-
-                               echo "<table>\n";
-                               echo "<tr><th class=\"data\" colspan=\"3\">{$lang['strfktarget']}</th></tr>";
-                               echo "<tr><th class=\"data\">{$lang['strtablecolumnlist']}</th><th class=\"data\">&nbsp;</th><th class=data>{$lang['strfkcolumnlist']}</th></tr>\n";
-                               echo "<tr><td class=\"data1\">" . $selColumns->fetch() . "</td>\n";
-                               echo "<td class=\"data1\" align=\"center\">" . $buttonRemove->fetch() . $buttonAdd->fetch() . "</td>";
-                               echo "<td class=\"data1\">" . $selIndex->fetch() . "</td></tr>\n";
-                               echo "<tr><th class=\"data\" colspan=\"3\">{$lang['stractions']}</th></tr>";
-                               echo "<tr>";
-                               echo "<td class=\"data1\" colspan=\"3\">\n";                            
-                               // ON SELECT actions
-                               echo "{$lang['stronupdate']} <select name=\"upd_action\">";
-                               foreach ($data->fkactions as $v) {
-                                       echo "<option value=\"{$v}\"", ($_POST['upd_action'] == $v) ? ' selected="selected"' : '', ">{$v}</option>\n";
-                               }
-                               echo "</select><br />\n";
-                               // ON DELETE actions
-                               echo "{$lang['strondelete']} <select name=\"del_action\">";
-                               foreach ($data->fkactions as $v) {
-                                       echo "<option value=\"{$v}\"", ($_POST['del_action'] == $v) ? ' selected="selected"' : '', ">{$v}</option>\n";
-                               }
-                               echo "</select><br />\n";
-                               // MATCH options
-                               echo "<select name=\"match\">";
-                               foreach ($data->fkmatches as $v) {
-                                       echo "<option value=\"{$v}\"", ($_POST['match'] == $v) ? ' selected="selected"' : '', ">{$v}</option>\n";
-                               }
-                               echo "</select><br />\n";
-                               // DEFERRABLE options
-                               echo "<select name=\"deferrable\">";
-                               foreach ($data->fkdeferrable as $v) {
-                                       echo "<option value=\"{$v}\"", ($_POST['deferrable'] == $v) ? ' selected="selected"' : '', ">{$v}</option>\n";
+                                       $selIndex = new XHTML_select('IndexColumnList[]', true, 10);
+                                       $selIndex->set_style('width: 10em;');
+                                       $selIndex->set_attribute('id', 'IndexColumnList');
+                                       $buttonAdd = new XHTML_Button('add', '>>');
+                                       $buttonAdd->set_attribute('onclick', 'buttonPressed(this);');
+                                       $buttonAdd->set_attribute('type', 'button');
+
+                                       $buttonRemove = new XHTML_Button('remove', '<<');
+                                       $buttonRemove->set_attribute('onclick', 'buttonPressed(this);');
+                                       $buttonRemove->set_attribute('type', 'button');
+
+                                       echo "<form onsubmit=\"doSelectAll();\" name=\"formIndex\" action=\"$PHP_SELF\" method=\"post\">\n";    
+
+                                       echo "<table>\n";
+                                       echo "<tr><th class=\"data\" colspan=\"3\">{$lang['strfktarget']}</th></tr>";
+                                       echo "<tr><th class=\"data\">{$lang['strtablecolumnlist']}</th><th class=\"data\">&nbsp;</th><th class=data>{$lang['strfkcolumnlist']}</th></tr>\n";
+                                       echo "<tr><td class=\"data1\">" . $selColumns->fetch() . "</td>\n";
+                                       echo "<td class=\"data1\" align=\"center\">" . $buttonRemove->fetch() . $buttonAdd->fetch() . "</td>";
+                                       echo "<td class=\"data1\">" . $selIndex->fetch() . "</td></tr>\n";
+                                       echo "<tr><th class=\"data\" colspan=\"3\">{$lang['stractions']}</th></tr>";
+                                       echo "<tr>";
+                                       echo "<td class=\"data1\" colspan=\"3\">\n";                            
+                                       // ON SELECT actions
+                                       echo "{$lang['stronupdate']} <select name=\"upd_action\">";
+                                       foreach ($data->fkactions as $v)
+                                               echo "<option value=\"{$v}\"", ($_POST['upd_action'] == $v) ? ' selected="selected"' : '', ">{$v}</option>\n";
+                                       echo "</select><br />\n";
+
+                                       // ON DELETE actions
+                                       echo "{$lang['strondelete']} <select name=\"del_action\">";
+                                       foreach ($data->fkactions as $v)
+                                               echo "<option value=\"{$v}\"", ($_POST['del_action'] == $v) ? ' selected="selected"' : '', ">{$v}</option>\n";
+                                       echo "</select><br />\n";
+
+                                       // MATCH options
+                                       echo "<select name=\"match\">";
+                                       foreach ($data->fkmatches as $v)
+                                               echo "<option value=\"{$v}\"", ($_POST['match'] == $v) ? ' selected="selected"' : '', ">{$v}</option>\n";
+                                       echo "</select><br />\n";
+
+                                       // DEFERRABLE options
+                                       echo "<select name=\"deferrable\">";
+                                       foreach ($data->fkdeferrable as $v)
+                                               echo "<option value=\"{$v}\"", ($_POST['deferrable'] == $v) ? ' selected="selected"' : '', ">{$v}</option>\n";
+                                       echo "</select><br />\n";
+
+                                       // INITIALLY options
+                                       echo "<select name=\"initially\">";
+                                       foreach ($data->fkinitial as $v)
+                                               echo "<option value=\"{$v}\"", ($_POST['initially'] == $v) ? ' selected="selected"' : '', ">{$v}</option>\n";
+                                       echo "</select>\n";
+                                       echo "</td></tr>\n";
+                                       echo "</table>\n";
+
+                                       echo "<p><input type=\"hidden\" name=\"action\" value=\"save_add_foreign_key\" />\n";
+                                       echo $misc->form;
+                                       echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
+                                       echo "<input type=\"hidden\" name=\"name\" value=\"", htmlspecialchars($_REQUEST['name']), "\" />\n";
+                                       echo "<input type=\"hidden\" name=\"target\" value=\"", htmlspecialchars(serialize($_REQUEST['target'])), "\" />\n";
+                                       echo "<input type=\"hidden\" name=\"SourceColumnList\" value=\"", htmlspecialchars($_REQUEST['SourceColumnList']), "\" />\n";
+                                       echo "<input type=\"hidden\" name=\"stage\" value=\"3\" />\n";
+                                       echo "<input type=\"submit\" value=\"{$lang['stradd']}\" />\n";
+                                       echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
+                                       echo "</form>\n";
                                }
-                               echo "</select><br />\n";
-                               // INITIALLY options
-                               echo "<select name=\"initially\">";
-                               foreach ($data->fkinitial as $v) {
-                                       echo "<option value=\"{$v}\"", ($_POST['initially'] == $v) ? ' selected="selected"' : '', ">{$v}</option>\n";
-                               }
-                               echo "</select>\n";
-                               echo "</td></tr>";
-                               echo "</table>\n";
-
-                               echo "<p><input type=\"hidden\" name=\"action\" value=\"save_add_foreign_key\" />\n";
-                               echo $misc->form;
-                               echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
-                               echo "<input type=\"hidden\" name=\"name\" value=\"", htmlspecialchars($_REQUEST['name']), "\" />\n";
-                               echo "<input type=\"hidden\" name=\"target\" value=\"", htmlspecialchars(serialize($_REQUEST['target'])), "\" />\n";
-                               echo "<input type=\"hidden\" name=\"SourceColumnList\" value=\"", htmlspecialchars($_REQUEST['SourceColumnList']), "\" />\n";
-                               echo "<input type=\"hidden\" name=\"stage\" value=\"3\" />\n";
-                               echo "<input type=\"submit\" value=\"{$lang['stradd']}\" />\n";
-                               echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
-                               echo "</form>\n";
                                break;
                        case 3:
                                // Unserialize target
                                echo "<form onsubmit=\"doSelectAll();\" name=\"formIndex\" action=\"$PHP_SELF\" method=\"post\">\n";    
 
                                echo "<table>\n";
-                               echo "<tr><th class=\"data\" colspan=\"3\">{$lang['strname']}</th></tr>";
-                               echo "<tr>";
-                               echo "<td class=\"data1\" colspan=\"3\"><input type=\"text\" name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" /></td></tr>";
-                               echo "<tr><th class=\"data\">{$lang['strtablecolumnlist']}</th><th class=\"data\">&nbsp;</th><th class=data>{$lang['strfkcolumnlist']}</th></tr>\n";
+                               echo "<tr><th class=\"data\" colspan=\"3\">{$lang['strname']}</th></tr>\n";
+                               echo "<tr><td class=\"data1\" colspan=\"3\"><input type=\"text\" name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" /></td></tr>\n";
+                               echo "<tr><th class=\"data\">{$lang['strtablecolumnlist']}</th><th class=\"data\">&nbsp;</th><th class=\"data required\">{$lang['strfkcolumnlist']}</th></tr>\n";
                                echo "<tr><td class=\"data1\">" . $selColumns->fetch() . "</td>\n";
-                               echo "<td class=\"data1\" align=\"center\">" . $buttonRemove->fetch() . $buttonAdd->fetch() . "</td>";
+                               echo "<td class=\"data1\" align=\"center\">" . $buttonRemove->fetch() . $buttonAdd->fetch() . "</td>\n";
                                echo "<td class=data1>" . $selIndex->fetch() . "</td></tr>\n";
                                echo "<tr><th class=\"data\" colspan=\"3\">{$lang['strfktarget']}</th></tr>";
                                echo "<tr>";
                        echo "<tr>";
                        echo "<td class=\"data1\" colspan=\"3\"><input type=\"text\" name=\"name\" value=\"", htmlspecialchars($_POST['name']), 
                                "\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" /></td></tr>";
-                       echo "<tr><th class=\"data\">{$lang['strtablecolumnlist']}</th><th class=\"data\">&nbsp;</th><th class=data>{$lang['strindexcolumnlist']}</th></tr>\n";
+                       echo "<tr><th class=\"data\">{$lang['strtablecolumnlist']}</th><th class=\"data\">&nbsp;</th><th class=\"data required\">{$lang['strindexcolumnlist']}</th></tr>\n";
                        echo "<tr><td class=\"data1\">" . $selColumns->fetch() . "</td>\n";
                        echo "<td class=\"data1\" align=\"center\">" . $buttonRemove->fetch() . $buttonAdd->fetch() . "</td>";
                        echo "<td class=data1>" . $selIndex->fetch() . "</td></tr>\n";