home *** CD-ROM | disk | FTP | other *** search
/ Freelog 70 / Freelog070.iso / Internet / EasyPHP / easyphp1-8_setup.exe / {app} / phpmyadmin / tbl_relation.php < prev    next >
Encoding:
PHP Script  |  2004-11-14  |  27.1 KB  |  629 lines

  1. <?php
  2. /* $Id: tbl_relation.php,v 2.20 2004/11/14 13:17:59 lem9 Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5. /**
  6.  * Gets some core libraries
  7.  */
  8. require_once('./libraries/grab_globals.lib.php');
  9. require_once('./libraries/common.lib.php');
  10. require_once('./tbl_properties_common.php');
  11. $url_query .= '&goto=tbl_properties.php';
  12.  
  13.  
  14. /**
  15.  * Gets tables informations
  16.  */
  17. require('./tbl_properties_table_info.php');
  18.  
  19. // Note: in tbl_properties_links.php we get and display the table comment.
  20. // For InnoDB, this comment contains the REFER information but any update
  21. // has not been done yet (will be done in tbl_relation.php later).
  22. $avoid_show_comment = TRUE;
  23.  
  24. /**
  25.  * Displays top menu links
  26.  */
  27. require('./tbl_properties_links.php');
  28.  
  29. require_once('./libraries/relation.lib.php');
  30.  
  31. $options_array = array('CASCADE' => 'CASCADE', 'SET_NULL' => 'SET NULL', 'NO_ACTION' => 'NO ACTION', 'RESTRICT' => 'RESTRICT');
  32.  
  33.          /**
  34.          * Generate dropdown choices
  35.          *
  36.          * @param   string   Message to display
  37.          * @param   string   Name of the <select> field
  38.          * @param   array    Choices for dropdown
  39.          * @return  string   The existing value (for selected)
  40.          *
  41.          * @access  public
  42.          */
  43. function PMA_generate_dropdown($dropdown_question,$radio_name,$choices,$selected_value) {
  44.     global $font_smallest;
  45.  
  46.     echo $dropdown_question . '  ';
  47.  
  48.     //echo '<select name="' . $radio_name . '" style="font-size: ' . $font_smallest . '">' . "\n";
  49.     //echo '<option value="nix" style="font-size: ' . $font_smallest . '" >--</option>' . "\n";
  50.     echo '<select name="' . $radio_name . '">' . "\n";
  51.     echo '<option value="nix">--</option>' . "\n";
  52.  
  53.     foreach ($choices AS $one_value => $one_label) {
  54.         echo '<option value="' . $one_value . '"';
  55.         if ($selected_value == $one_value) {
  56.             echo ' selected="selected" ';
  57.         }
  58.         //echo ' style="font-size: ' . $font_smallest . '">'
  59.         echo '>' . $one_label . '</option>' . "\n";
  60.     }
  61.     echo '</select>' . "\n";
  62.     echo "\n";
  63. }
  64.  
  65.  
  66. /**
  67.  * Gets the relation settings
  68.  */
  69. $cfgRelation = PMA_getRelationsParam();
  70.  
  71.  
  72. /**
  73.  * Updates
  74.  */
  75.  
  76. // ensure we are positionned to our current db (since the previous reading
  77. // of relations makes pmadb the current one, maybe depending on the MySQL version)
  78. PMA_DBI_select_db($db);
  79.  
  80. if ($cfgRelation['relwork']) {
  81.     $existrel = PMA_getForeigners($db, $table, '', 'internal');
  82. }
  83. if ($tbl_type=='INNODB') {
  84.     $existrel_innodb = PMA_getForeigners($db, $table, '', 'innodb');
  85. }
  86. if ($cfgRelation['displaywork']) {
  87.     $disp     = PMA_getDisplayField($db, $table);
  88. }
  89.  
  90. // updates for internal relations or innodb?
  91. if (isset($submit_rel) && $submit_rel == 'true') {
  92.     // u p d a t e s   f o r   I n t e r n a l    r e l a t i o n s
  93.     if ($cfgRelation['relwork']) {
  94.  
  95.         foreach ($destination AS $master_field => $foreign_string) {
  96.             if ($foreign_string != 'nix') {
  97.                 list($foreign_db, $foreign_table, $foreign_field) = explode('.', $foreign_string);
  98.                 if (!isset($existrel[$master_field])) {
  99.                     $upd_query  = 'INSERT INTO ' . PMA_backquote($cfgRelation['relation'])
  100.                                 . '(master_db, master_table, master_field, foreign_db, foreign_table, foreign_field)'
  101.                                 . ' values('
  102.                                 . '\'' . PMA_sqlAddslashes($db) . '\', '
  103.                                 . '\'' . PMA_sqlAddslashes($table) . '\', '
  104.                                 . '\'' . PMA_sqlAddslashes($master_field) . '\', '
  105.                                 . '\'' . PMA_sqlAddslashes($foreign_db) . '\', '
  106.                                 . '\'' . PMA_sqlAddslashes($foreign_table) . '\','
  107.                                 . '\'' . PMA_sqlAddslashes($foreign_field) . '\')';
  108.                 } else if ($existrel[$master_field]['foreign_db'] . '.' .$existrel[$master_field]['foreign_table'] . '.' . $existrel[$master_field]['foreign_field'] != $foreign_string) {
  109.                     $upd_query  = 'UPDATE ' . PMA_backquote($cfgRelation['relation']) . ' SET'
  110.                                 . ' foreign_db       = \'' . PMA_sqlAddslashes($foreign_db) . '\', '
  111.                                 . ' foreign_table    = \'' . PMA_sqlAddslashes($foreign_table) . '\', '
  112.                                 . ' foreign_field    = \'' . PMA_sqlAddslashes($foreign_field) . '\' '
  113.                                 . ' WHERE master_db  = \'' . PMA_sqlAddslashes($db) . '\''
  114.                                 . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\''
  115.                                 . ' AND master_field = \'' . PMA_sqlAddslashes($master_field) . '\'';
  116.                 } // end if... else....
  117.             } else if (isset($existrel[$master_field])) {
  118.                 $upd_query      = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
  119.                                 . ' WHERE master_db  = \'' . PMA_sqlAddslashes($db) . '\''
  120.                                 . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\''
  121.                                 . ' AND master_field = \'' . PMA_sqlAddslashes($master_field) . '\'';
  122.             } // end if... else....
  123.             if (isset($upd_query)) {
  124.                 $upd_rs         = PMA_query_as_cu($upd_query);
  125.                 unset($upd_query);
  126.             }
  127.         } // end while
  128.     } // end if (updates for internal relations)
  129.  
  130.     // u p d a t e s   f o r   I n n o D B
  131.     // ( for now, one index name only; we keep the definitions if the
  132.     // foreign db is not the same)
  133.     if (isset($destination_innodb)) {
  134.         foreach ($destination_innodb AS $master_field => $foreign_string) {
  135.             if ($foreign_string != 'nix') {
  136.                 list($foreign_db, $foreign_table, $foreign_field) = explode('.', $foreign_string);
  137.                 if (!isset($existrel_innodb[$master_field])) {
  138.                     // no key defined for this field
  139.  
  140.                     // The next few lines are repeated below, so they
  141.                     // could be put in an include file
  142.                     // Note: I tried to enclose the db and table name with
  143.                     // backquotes but MySQL 4.0.16 did not like the syntax
  144.                     // (for example: `base2`.`table1` )
  145.  
  146.                     $upd_query  = 'ALTER TABLE ' . PMA_backquote($table)
  147.                                 . ' ADD FOREIGN KEY ('
  148.                                 . PMA_backquote(PMA_sqlAddslashes($master_field)) . ')'
  149.                                 . ' REFERENCES '
  150.                                 . PMA_backquote(PMA_sqlAddslashes($foreign_db) . '.'
  151.                                 . PMA_sqlAddslashes($foreign_table)) . '('
  152.                                 . PMA_backquote(PMA_sqlAddslashes($foreign_field)) . ')';
  153.  
  154.                     if (${$master_field . '_on_delete'} != 'nix') {
  155.                         $upd_query   .= ' ON DELETE ' . $options_array[${$master_field . '_on_delete'}];
  156.                     }
  157.                     if (${$master_field . '_on_update'} != 'nix') {
  158.                         $upd_query   .= ' ON UPDATE ' . $options_array[${$master_field . '_on_update'}];
  159.                     }
  160.  
  161.                     // end repeated code
  162.  
  163.                 } else if (($existrel_innodb[$master_field]['foreign_db'] . '.' .$existrel_innodb[$master_field]['foreign_table'] . '.' . $existrel_innodb[$master_field]['foreign_field'] != $foreign_string)
  164.                   || ( ${$master_field . '_on_delete'} != (!empty($existrel_innodb[$master_field]['on_delete']) ? $existrel_innodb[$master_field]['on_delete'] : ''))
  165.                   || ( ${$master_field . '_on_update'} != (!empty($existrel_innodb[$master_field]['on_update']) ? $existrel_innodb[$master_field]['on_update'] : ''))
  166.                        ) {
  167.                     // another foreign key is already defined for this field
  168.                     // or
  169.                     // an option has been changed for ON DELETE or ON UPDATE
  170.  
  171.                     // remove existing key
  172.                     if (PMA_MYSQL_INT_VERSION >= 40013) {
  173.                         $upd_query  = 'ALTER TABLE ' . PMA_backquote($table)
  174.                                     . ' DROP FOREIGN KEY '
  175.                                     . PMA_backquote($existrel_innodb[$master_field]['constraint']);
  176.  
  177.                         // I tried to send both in one query but it failed
  178.                         $upd_rs     = PMA_DBI_query($upd_query);
  179.                     }
  180.  
  181.                     // add another
  182.                     $upd_query  = 'ALTER TABLE ' . PMA_backquote($table)
  183.                                 . ' ADD FOREIGN KEY ('
  184.                                 . PMA_backquote(PMA_sqlAddslashes($master_field)) . ')'
  185.                                 . ' REFERENCES '
  186.                                 . PMA_backquote(PMA_sqlAddslashes($foreign_db) . '.'
  187.                                 . PMA_sqlAddslashes($foreign_table)) . '('
  188.                                 . PMA_backquote(PMA_sqlAddslashes($foreign_field)) . ')';
  189.  
  190.                     if (${$master_field . '_on_delete'} != 'nix') {
  191.                         $upd_query   .= ' ON DELETE ' . $options_array[${$master_field . '_on_delete'}];
  192.                     }
  193.                     if (${$master_field . '_on_update'} != 'nix') {
  194.                         $upd_query   .= ' ON UPDATE ' . $options_array[${$master_field . '_on_update'}];
  195.                     }
  196.  
  197.                 } // end if... else....
  198.             } else if (isset($existrel_innodb[$master_field])) {
  199.                     if (PMA_MYSQL_INT_VERSION >= 40013) {
  200.                         $upd_query  = 'ALTER TABLE ' . PMA_backquote($table)
  201.                                 . ' DROP FOREIGN KEY '
  202.                                 . PMA_backquote($existrel_innodb[$master_field]['constraint']);
  203.                     }
  204.             } // end if... else....
  205.  
  206.             if (isset($upd_query)) {
  207.                 $upd_rs    = PMA_DBI_try_query($upd_query);
  208.                 $tmp_error = PMA_DBI_getError();
  209.                 if (substr($tmp_error, 1, 4) == '1216') {
  210.                     PMA_mysqlDie($tmp_error, $upd_query, FALSE, '', FALSE);
  211.                     echo PMA_showMySQLDocu('manual_Table_types', 'InnoDB_foreign_key_constraints') . "\n";
  212.                 }
  213.                 if (substr($tmp_error, 1, 4) == '1005') {
  214.                     echo '<p class="warning">' . $strNoIndex . ' (' . $master_field .')</p>'  . PMA_showMySQLDocu('manual_Table_types', 'InnoDB_foreign_key_constraints') . "\n";
  215.                 }
  216.                 unset($upd_query);
  217.                 unset($tmp_error);
  218.             }
  219.         } // end while
  220.     } // end if isset($destination_innodb)
  221.  
  222. } // end if (updates for internal relations or InnoDB)
  223.  
  224.  
  225. // U p d a t e s   f o r   d i s p l a y   f i e l d
  226.  
  227. if ($cfgRelation['displaywork']
  228.     && isset($submit_show) && $submit_show == 'true') {
  229.  
  230.     if ($disp) {
  231.         if ($display_field != '') {
  232.             $upd_query = 'UPDATE ' . PMA_backquote($cfgRelation['table_info'])
  233.                        . ' SET display_field = \'' . PMA_sqlAddslashes($display_field) . '\''
  234.                        . ' WHERE db_name  = \'' . PMA_sqlAddslashes($db) . '\''
  235.                        . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
  236.         } else {
  237.             $upd_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_info'])
  238.                        . ' WHERE db_name  = \'' . PMA_sqlAddslashes($db) . '\''
  239.                        . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
  240.         }
  241.     } elseif ($display_field != '') {
  242.         $upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['table_info'])
  243.                    . '(db_name, table_name, display_field) '
  244.                    . ' VALUES('
  245.                    . '\'' . PMA_sqlAddslashes($db) . '\','
  246.                    . '\'' . PMA_sqlAddslashes($table) . '\','
  247.                    . '\'' . PMA_sqlAddslashes($display_field) . '\')';
  248.     }
  249.  
  250.     if (isset($upd_query)) {
  251.         $upd_rs    = PMA_query_as_cu($upd_query);
  252.     }
  253. } // end if
  254.  
  255. if ($cfgRelation['commwork']
  256.     && isset($submit_comm) && $submit_comm == 'true') {
  257.     foreach ($comment AS $key => $value) {
  258.         // garvin: I exported the snippet here to a function (relation.lib.php) , so it can be used multiple times throughout other pages where you can set comments.
  259.         PMA_setComment($db, $table, $key, $value);
  260.     }  // end while (transferred data)
  261. } // end if (commwork)
  262.  
  263. // If we did an update, refresh our data
  264. if (isset($submit_rel) && $submit_rel == 'true') {
  265.     if ($cfgRelation['relwork']) {
  266.         $existrel = PMA_getForeigners($db, $table, '', 'internal');
  267.     }
  268.     if ($tbl_type=='INNODB') {
  269.         $existrel_innodb = PMA_getForeigners($db, $table, '', 'innodb');
  270.     }
  271. }
  272. if ($cfgRelation['displaywork']) {
  273.     $disp     = PMA_getDisplayField($db, $table);
  274. }
  275. if ($cfgRelation['commwork']) {
  276.     $comments = PMA_getComments($db, $table);
  277. }
  278.  
  279.  
  280. /**
  281.  * Dialog
  282.  */
  283. if ($cfgRelation['relwork'] || $tbl_type=='INNODB') {
  284.     // To choose relations we first need all tables names in current db
  285.     // and if PMA version permits and the main table is innodb,
  286.     // we use SHOW TABLE STATUS because we need to find other InnoDB tables
  287.  
  288.     if ($tbl_type=='INNODB') {
  289.         $tab_query           = 'SHOW TABLE STATUS FROM ' . PMA_backquote($db);
  290.     // [0] of the row is the name
  291.     // [1] is the type
  292.     } else {
  293.         $tab_query           = 'SHOW TABLES FROM ' . PMA_backquote($db);
  294.     }
  295.     // [0] of the row is the name
  296.  
  297.     $tab_rs              = PMA_DBI_query($tab_query, NULL, PMA_DBI_QUERY_STORE);
  298.     $selectboxall['nix'] = '--';
  299.     $selectboxall_innodb['nix'] = '--';
  300.  
  301.     while ($curr_table = @PMA_DBI_fetch_row($tab_rs)) {
  302.         if (($curr_table[0] != $table) && ($curr_table[0] != $cfg['Server']['relation'])) {
  303.             PMA_DBI_select_db($db);
  304.  
  305.             // need to use PMA_DBI_QUERY_STORE with PMA_DBI_num_rows() in mysqli
  306.             $fi_rs    = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($curr_table[0]) . ';', NULL, PMA_DBI_QUERY_STORE);
  307.             if ($fi_rs && PMA_DBI_num_rows($fi_rs) > 0) {
  308.                 $seen_a_primary = FALSE;
  309.                 while ($curr_field = PMA_DBI_fetch_assoc($fi_rs)) {
  310.                     if (isset($curr_field['Key_name']) && $curr_field['Key_name'] == 'PRIMARY') {
  311.                         $seen_a_primary = TRUE;
  312.                         $field_full = $db . '.' .$curr_field['Table'] . '.' . $curr_field['Column_name'];
  313.                         $field_v    = $curr_field['Table'] . '->' . $curr_field['Column_name'];
  314.                         $selectboxall[$field_full] =  $field_v;
  315.                         // there could be more than one segment of the primary
  316.                         // so do not break
  317.  
  318.                         // Please watch here, tbl_type is INNODB but the
  319.                         // resulting value of SHOW KEYS is InnoDB
  320.  
  321.                         if ($tbl_type=='INNODB' && isset($curr_table[1]) && $curr_table[1]=='InnoDB') {
  322.                             $selectboxall_innodb[$field_full] =  $field_v;
  323.                         }
  324.  
  325.                     } else if (isset($curr_field['Non_unique']) && $curr_field['Non_unique'] == 0 && $seen_a_primary==FALSE) {
  326.                         // if we can't find a primary key we take any unique one
  327.                         // (in fact, we show all segments of unique keys
  328.                         //  and all unique keys)
  329.                         $field_full = $db . '.' . $curr_field['Table'] . '.' . $curr_field['Column_name'];
  330.                         $field_v    = $curr_field['Table'] . '->' . $curr_field['Column_name'];
  331.                         $selectboxall[$field_full] =  $field_v;
  332.                         if ($tbl_type=='INNODB' && isset($curr_table[1]) && $curr_table[1]=='InnoDB') {
  333.                             $selectboxall_innodb[$field_full] =  $field_v;
  334.                         }
  335.  
  336.                     // for InnoDB, any index is allowed
  337.                     } else if ($tbl_type=='INNODB' && isset($curr_table[1]) && $curr_table[1]=='InnoDB') {
  338.                         $field_full = $db . '.' . $curr_field['Table'] . '.' . $curr_field['Column_name'];
  339.                         $field_v    = $curr_field['Table'] . '->' . $curr_field['Column_name'];
  340.                         $selectboxall_innodb[$field_full] =  $field_v;
  341.  
  342.                     } // end if
  343.                 } // end while over keys
  344.             } // end if (PMA_DBI_num_rows)
  345.             PMA_DBI_free_result($fi_rs);
  346.             unset($fi_rs);
  347.         // Mike Beck - 24.07.02: i've been asked to add all keys of the
  348.         // current table (see bug report #574851)
  349.         }
  350.         else if ($curr_table[0] == $table) {
  351.             PMA_DBI_select_db($db);
  352.  
  353.             // need to use PMA_DBI_QUERY_STORE with PMA_DBI_num_rows() in mysqli
  354.             $fi_rs    = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($curr_table[0]) . ';', NULL, PMA_DBI_QUERY_STORE);
  355.             if ($fi_rs && PMA_DBI_num_rows($fi_rs) > 0) {
  356.                 while ($curr_field = PMA_DBI_fetch_assoc($fi_rs)) {
  357.                     $field_full = $db . '.' . $curr_field['Table'] . '.' . $curr_field['Column_name'];
  358.                     $field_v    = $curr_field['Table'] . '->' . $curr_field['Column_name'];
  359.                     $selectboxall[$field_full] =  $field_v;
  360.                     if ($tbl_type=='INNODB' && isset($curr_table[1]) && $curr_table[1]=='InnoDB') {
  361.                         $selectboxall_innodb[$field_full] =  $field_v;
  362.                     }
  363.                 } // end while
  364.             } // end if (PMA_DBI_num_rows)
  365.             PMA_DBI_free_result($fi_rs);
  366.             unset($fi_rs);
  367.         }
  368.     } // end while over tables
  369.  
  370. } // end if
  371.  
  372.  
  373. // Now find out the columns of our $table
  374. // need to use PMA_DBI_QUERY_STORE with PMA_DBI_num_rows() in mysqli
  375. $col_rs    = PMA_DBI_try_query('SHOW COLUMNS FROM ' . PMA_backquote($table) . ';', NULL, PMA_DBI_QUERY_STORE);
  376.  
  377. if ($col_rs && PMA_DBI_num_rows($col_rs) > 0) {
  378.     while ($row = PMA_DBI_fetch_assoc($col_rs)) {
  379.         $save_row[] = $row;
  380.     }
  381.     $saved_row_cnt  = count($save_row);
  382.     echo $tbl_type=='INNODB' ? '' : '<table border="0" cellpadding="0" cellspacing="0">' . "\n"
  383.                                   . '    <tr><td valign="top">' . "\n\n";
  384. ?>
  385.  
  386. <form method="post" action="tbl_relation.php">
  387.     <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  388.     <input type="hidden" name="submit_rel" value="true" />
  389.  
  390.     <table cellpadding="2" cellspacing="1">
  391.     <tr>
  392.         <th colspan="<?php echo $tbl_type=='INNODB' ? '4' : '2'; ?>" align="center" class="tblHeaders"><b><?php echo $strLinksTo; ?></b></th>
  393.     </tr>
  394.     <tr>
  395.         <th></th>
  396.         <?php
  397.         if ($cfgRelation['relwork']) {
  398.             echo '        <th><b>' .$strInternalRelations;
  399.             if ($tbl_type=='INNODB') {
  400.                 echo ' ' . PMA_showHint($strInternalNotNecessary);
  401.             }
  402.             echo '</b></th>';
  403.         }
  404.         if ($tbl_type=='INNODB') {
  405.             echo '<th colspan="2">InnoDB';
  406.             if (PMA_MYSQL_INT_VERSION < 40013) {
  407.                 echo ' (**)';
  408.             }
  409.             echo '</th>';
  410.         }
  411.         ?>
  412.     </tr>
  413.     <?php
  414.     for ($i = 0; $i < $saved_row_cnt; $i++) {
  415.         $myfield = $save_row[$i]['Field'];
  416.         echo "\n";
  417.         ?>
  418.     <tr>
  419.         <td align="center" bgcolor="<?php echo ($i % 2) ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo']; ?>"><b><?php echo $save_row[$i]['Field']; ?></b></td>
  420.         <?php
  421.         if ($cfgRelation['relwork']) { 
  422.         ?>
  423.         <td bgcolor="<?php echo ($i % 2) ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo']; ?>">
  424.             <select name="destination[<?php echo htmlspecialchars($save_row[$i]['Field']); ?>]">
  425.             <?php
  426.             echo "\n";
  427.  
  428.             // PMA internal relations
  429.             if (isset($existrel[$myfield])) {
  430.                 $foreign_field    = $existrel[$myfield]['foreign_db'] . '.'
  431.                          . $existrel[$myfield]['foreign_table'] . '.'
  432.                          . $existrel[$myfield]['foreign_field'];
  433.             } else {
  434.                 $foreign_field    = FALSE;
  435.             }
  436.             $seen_key = FALSE;
  437.             foreach ($selectboxall AS $key => $value) {
  438.                 echo '                '
  439.                      . '<option value="' . htmlspecialchars($key) . '"';
  440.                 if ($foreign_field && $key == $foreign_field) {
  441.                     echo ' selected="selected"';
  442.                     $seen_key = TRUE;
  443.                 }
  444.                 echo '>' . $value . '</option>'. "\n";
  445.             } // end while
  446.  
  447.         // if the link defined in relationtable points to a foreign field
  448.         // that is not a key in the foreign table, we show the link
  449.         // (will not be shown with an arrow)
  450.             if ($foreign_field && !$seen_key) {
  451.                 echo '                '
  452.                      . '<option value="' . htmlspecialchars($foreign_field) . '"';
  453.                 echo ' selected="selected"';
  454.                 echo '>' . $foreign_field . '</option>'. "\n";
  455.             }
  456.         ?>
  457.             </select>
  458.         </td>
  459.         <?php
  460.         } // end if (internal relations)
  461.  
  462.         if ($tbl_type=='INNODB') {
  463.             if (!empty($save_row[$i]['Key'])) {
  464.         ?>
  465.         <td bgcolor="<?php echo ($i % 2) ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo']; ?>">
  466.             <select name="destination_innodb[<?php echo htmlspecialchars($save_row[$i]['Field']); ?>]">
  467.         <?php
  468.                 if (isset($existrel_innodb[$myfield])) {
  469.                     $foreign_field    = $existrel_innodb[$myfield]['foreign_db'] . '.'
  470.                              . $existrel_innodb[$myfield]['foreign_table'] . '.'
  471.                              . $existrel_innodb[$myfield]['foreign_field'];
  472.                 } else {
  473.                     $foreign_field    = FALSE;
  474.                 }
  475.  
  476.                 $found_foreign_field = FALSE;
  477.                 foreach ($selectboxall_innodb AS $key => $value) {
  478.                     echo '                '
  479.                          . '<option value="' . htmlspecialchars($key) . '"';
  480.                     if ($foreign_field && $key == $foreign_field) {
  481.                         echo ' selected="selected"';
  482.                         $found_foreign_field = TRUE;
  483.                     }
  484.                     echo '>' . $value . '</option>'. "\n";
  485.                 } // end while
  486.  
  487.             // we did not find the foreign field in the tables of current db,
  488.             // must be defined in another db so show it to avoid erasing it
  489.                 if (!$found_foreign_field && $foreign_field) {
  490.                     echo '                '
  491.                          . '<option value="' . htmlspecialchars($foreign_field) . '"';
  492.                     echo ' selected="selected"';
  493.                     echo '>' . $foreign_field . '</option>'. "\n";
  494.                 }
  495.  
  496.         ?>
  497.                 </select>
  498.         </td>
  499.         <td bgcolor="<?php echo ($i % 2) ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo']; ?>">
  500.         <?php
  501.                   PMA_generate_dropdown('ON DELETE',
  502.                       htmlspecialchars($save_row[$i]['Field']) . '_on_delete',
  503.                       $options_array,
  504.                       (isset($existrel_innodb[$myfield]['on_delete']) ? $existrel_innodb[$myfield]['on_delete']: '') );
  505.  
  506.                   echo '   ';
  507.  
  508.                   PMA_generate_dropdown('ON UPDATE',
  509.                       htmlspecialchars($save_row[$i]['Field']) . '_on_update',
  510.                       $options_array,
  511.                       (isset($existrel_innodb[$myfield]['on_update']) ? $existrel_innodb[$myfield]['on_update']: '') );
  512.  
  513.                 } else {
  514.                     echo '<td>' . PMA_showHint($strNoIndex) . '</td>';
  515.                 } // end if (a key exists)
  516.             } // end if (InnoDB)
  517.         ?>
  518.         </td>
  519.     </tr>
  520.         <?php
  521.     } // end for
  522.  
  523.     echo "\n";
  524.     ?>
  525.     <tr>
  526.         <td colspan="<?php echo $tbl_type=='INNODB' ? '4' : '2'; ?>" align="center" class="tblFooters">
  527.             <input type="submit" value="<?php echo '  ' . $strGo . '  '; ?>" />
  528.         </td>
  529.     </tr>
  530.     </table>
  531.     <?php
  532.         if ($tbl_type=='INNODB') {
  533.             if (PMA_MYSQL_INT_VERSION < 40013) {
  534.                 echo '** ' . sprintf($strUpgrade, 'MySQL', '4.0.13') . '<br />';
  535.             }
  536.         }
  537.     ?>
  538. </form>
  539.  
  540.     <?php
  541.     echo $tbl_type=='INNODB' ? '' : "\n\n" . '    </td>' . "\n";
  542.     if ($cfgRelation['displaywork']) {
  543.         echo $tbl_type=='INNODB' ? '' : '    <td>      </td>' . "\n"
  544.             . '    <td valign="top" align="center">' . "\n\n";
  545.         // Get "display_field" infos
  546.         $disp = PMA_getDisplayField($db, $table);
  547.  
  548.         echo "\n";
  549.         ?>
  550. <form method="post" action="tbl_relation.php">
  551.     <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  552.     <input type="hidden" name="submit_show" value="true" />
  553.  
  554.     <p><b><?php echo $strChangeDisplay . ': '; ?></b><br />
  555.     <select name="display_field" onchange="this.form.submit();" style="vertical-align: middle">
  556.         <option value="">---</option>
  557.         <?php
  558.         echo "\n";
  559.         foreach ($save_row AS $row) {
  560.             echo '        <option value="' . htmlspecialchars($row['Field']) . '"';
  561.             if (isset($disp) && $row['Field'] == $disp) {
  562.                 echo ' selected="selected"';
  563.             }
  564.             echo '>' . htmlspecialchars($row['Field']) . '</option>'. "\n";
  565.         } // end while
  566.         ?>
  567.     </select>
  568.     <script type="text/javascript" language="javascript">
  569.     <!--
  570.     // Fake js to allow the use of the <noscript> tag
  571.     //-->
  572.     </script>
  573.     <noscript>
  574.         <input type="submit" value="<?php echo $strGo; ?>" style="vertical-align: middle" />
  575.     </noscript>
  576.     </p>
  577. </form>
  578.         <?php
  579.         echo $tbl_type=='INNODB' ? '' : "\n\n" . '    </td>' . "\n";
  580.     } // end if (displayworks)
  581.  
  582.     if ($cfgRelation['commwork']) {
  583.         echo $tbl_type=='INNODB' ? "\n" : '    <td>      </td>' . "\n"
  584.                                         . '    <td valign="top">' . "\n\n";
  585.         ?>
  586. <form method="post" action="tbl_relation.php">
  587.     <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  588.     <input type="hidden" name="submit_comm" value="true" />
  589.  
  590.     <table border="0" cellpadding="2" cellspacing="1">
  591.     <tr>
  592.         <th colspan="2" align="center" class="tblHeaders"><b><?php echo $strComments; ?></b></th>
  593.     </tr>
  594.         <?php
  595.         for ($i = 0; $i < $saved_row_cnt; $i++) {
  596.             $field = $save_row[$i]['Field'];
  597.             echo "\n";
  598.             ?>
  599.     <tr>
  600.         <td align="center" bgcolor="<?php echo ($i % 2) ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo']; ?>"><b><?php echo $field; ?></b></td>
  601.         <td bgcolor="<?php echo ($i % 2) ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo']; ?>">
  602.             <input type="text" name="comment[<?php echo $field; ?>]" value="<?php echo (isset($comments[$field]) ?  htmlspecialchars($comments[$field]) : ''); ?>" />
  603.         </td>
  604.     </tr>
  605.             <?php
  606.         } // end for
  607.  
  608.         echo "\n";
  609.         ?>
  610.     <tr>
  611.         <td colspan="2" align="center" class="tblFooters">
  612.             <input type="submit" value="<?php echo '  ' . $strGo . '  '; ?>" />
  613.         </td>
  614.     </tr>
  615.     </table>
  616. </form>
  617.         <?php
  618.     } //    end if (comments work)
  619.     echo $tbl_type=='INNODB' ? '' : "\n\n" . '    </td></tr>' . "\n"
  620.                                   . '</table>' . "\n\n";
  621. } // end if (we have columns in this table)
  622.  
  623.  
  624. /**
  625.  * Displays the footer
  626.  */
  627. require_once('./footer.inc.php');
  628. ?>
  629.