<tr id="id_tr_<?php echo $GLOBALS['PMD_URL']["TABLE_NAME_SMALL"][$i] . '.' . urlencode($tab_column[$t_n]["COLUMN_NAME"][$j]); ?> " <?php if ($display_field == $tab_column[$t_n]["COLUMN_NAME"][$j]) { echo ' class="tab_field_3" '; } else { echo ' class="tab_field" '; } ?> onmouseover="old_class = this.className; this.className = 'tab_field_2';" onmouseout="this.className = old_class;" onmousedown="Click_field('<?php echo $GLOBALS['PMD_URL']["TABLE_NAME_SMALL"][$i] . "','" . urlencode($tab_column[$t_n]["COLUMN_NAME"][$j]) . "',"; if (!PMA_isForeignKeySupported($GLOBALS['PMD']['TABLE_TYPE'][$i])) { echo isset($tables_pk_or_unique_keys[$t_n . "." . $tab_column[$t_n]["COLUMN_NAME"][$j]]) ? 1 : 0; } else { // if foreign keys are supported, it's not necessary that the // index is a primary key echo isset($tables_all_keys[$t_n . "." . $tab_column[$t_n]["COLUMN_NAME"][$j]]) ? 1 : 0; } ?> )"> <?php if (isset($_REQUEST['query'])) { echo '<td class="select_all">'; echo '<input value="' . htmlspecialchars($t_n_url) . urlencode($tab_column[$t_n]["COLUMN_NAME"][$j]) . '"'; echo 'type="checkbox" id="select_' . htmlspecialchars($t_n_url) . '._' . urlencode($tab_column[$t_n]["COLUMN_NAME"][$j]) . '" '; echo 'style="margin: 0px;" title="select_' . urlencode($tab_column[$t_n]["COLUMN_NAME"][$j]) . '" '; echo 'onclick="store_column(\'' . urlencode($GLOBALS['PMD_OUT']["TABLE_NAME_SMALL"][$i]) . '\',\'' . htmlspecialchars($GLOBALS['PMD_OUT']["OWNER"][$i]) . '\',\'' . urlencode($tab_column[$t_n]["COLUMN_NAME"][$j]) . '\')"></td>';
/** * process internal and foreign key relations * * @param string $db The database name * @param integer $pageNumber document number/Id * @param array $cfgRelation relation settings * * @return void * @access private */ public function processRelations($db, $pageNumber, $cfgRelation) { /* * A u t o m a t i c l a y o u t * * There are 2 kinds of relations in PMA * 1) Internal Relations 2) Foreign Key Relations */ if (isset($this->autoLayoutInternal) || isset($this->autoLayoutForeign)) { $all_tables = array(); } if (isset($this->autoLayoutForeign)) { /* * get the tables list * who support FOREIGN KEY, it's not * important that we group together InnoDB tables * and PBXT tables, as this logic is just to put * the tables on the layout, not to determine relations */ $tables = PMA_DBI_get_tables_full($db); $foreignkey_tables = array(); foreach ($tables as $table_name => $table_properties) { if (PMA_isForeignKeySupported($table_properties['ENGINE'])) { $foreignkey_tables[] = $table_name; } } $all_tables = $foreignkey_tables; /* * could be improved by finding the tables which have the * most references keys and placing them at the beginning * of the array (so that they are all center of schema) */ unset($tables, $foreignkey_tables); } if (isset($this->autoLayoutInternal)) { /* * get the tables list who support Internal Relations; * This type of relations will be created when * you setup the PMA tables correctly */ $master_tables = 'SELECT COUNT(master_table), master_table' . ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) . ' WHERE master_db = \'' . PMA_sqlAddSlashes($db) . '\'' . ' GROUP BY master_table' . ' ORDER BY COUNT(master_table) DESC'; $master_tables_rs = PMA_query_as_controluser($master_tables, false, PMA_DBI_QUERY_STORE); if ($master_tables_rs && PMA_DBI_num_rows($master_tables_rs) > 0) { /* first put all the master tables at beginning * of the list, so they are near the center of * the schema */ while (list(, $master_table) = PMA_DBI_fetch_row($master_tables_rs)) { $all_tables[] = $master_table; } /* Now for each master, add its foreigns into an array * of foreign tables, if not already there * (a foreign might be foreign for more than * one table, and might be a master itself) */ $foreign_tables = array(); foreach ($all_tables as $master_table) { $foreigners = PMA_getForeigners($db, $master_table); foreach ($foreigners as $foreigner) { if (!in_array($foreigner['foreign_table'], $foreign_tables)) { $foreign_tables[] = $foreigner['foreign_table']; } } } /* * Now merge the master and foreign arrays/tables */ foreach ($foreign_tables as $foreign_table) { if (!in_array($foreign_table, $all_tables)) { $all_tables[] = $foreign_table; } } } } if (isset($this->autoLayoutInternal) || isset($this->autoLayoutForeign)) { $this->addRelationCoordinates($all_tables, $pageNumber, $db, $cfgRelation); } $this->chosenPage = $pageNumber; }
* */ require_once './libraries/common.inc.php'; require_once 'libraries/pmd_common.php'; extract($_POST, EXTR_SKIP); extract($_GET, EXTR_SKIP); $die_save_pos = 0; require_once 'pmd_save_pos.php'; list($DB1, $T1) = explode(".", $T1); list($DB2, $T2) = explode(".", $T2); $tables = PMA_DBI_get_tables_full($db, $T1); $type_T1 = strtoupper($tables[$T1]['ENGINE']); $tables = PMA_DBI_get_tables_full($db, $T2); $type_T2 = strtoupper($tables[$T2]['ENGINE']); $try_to_delete_internal_relation = false; if (PMA_isForeignKeySupported($type_T1) && PMA_isForeignKeySupported($type_T2) && $type_T1 == $type_T2) { // InnoDB $existrel_foreign = PMA_getForeigners($DB2, $T2, '', 'foreign'); if (isset($existrel_foreign[$F2]['constraint'])) { $upd_query = 'ALTER TABLE ' . PMA_backquote($T2) . ' DROP FOREIGN KEY ' . PMA_backquote($existrel_foreign[$F2]['constraint']) . ';'; $upd_rs = PMA_DBI_query($upd_query); } else { // there can be an internal relation even if InnoDB $try_to_delete_internal_relation = true; } } else { $try_to_delete_internal_relation = true; } if ($try_to_delete_internal_relation) { // internal relations PMA_query_as_controluser('DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . $cfg['Server']['relation'] . ' WHERE ' . 'master_db = \'' . PMA_sqlAddSlashes($DB2) . '\'' . ' AND master_table = \'' . PMA_sqlAddSlashes($T2) . '\'' . ' AND master_field = \'' . PMA_sqlAddSlashes($F2) . '\'' . ' AND foreign_db = \'' . PMA_sqlAddSlashes($DB1) . '\'' . ' AND foreign_table = \'' . PMA_sqlAddSlashes($T1) . '\'' . ' AND foreign_field = \'' . PMA_sqlAddSlashes($F1) . '\'', false, PMA_DBI_QUERY_STORE);
} ?> <a href="tbl_printview.php?<?php echo $url_query; ?> "><?php echo PMA_getIcon('b_print.png', __('Print view'), true); ?> </a> <?php if (!$tbl_is_view && !$db_is_information_schema) { // if internal relations are available, or foreign keys are supported // ($tbl_storage_engine comes from libraries/tbl_info.inc.php) if ($cfgRelation['relwork'] || PMA_isForeignKeySupported($tbl_storage_engine)) { ?> <a href="tbl_relation.php?<?php echo $url_query; ?> "><?php echo PMA_getIcon('b_relations.png', __('Relation view'), true); ?> </a> <?php } if (!PMA_DRIZZLE) { ?> <a href="sql.php?<?php echo $url_query; ?>
echo '>' . htmlspecialchars($value) . '</option>' . "\n"; } // end while // if the link defined in relationtable points to a foreign field // that is not a key in the foreign table, we show the link // (will not be shown with an arrow) if ($foreign_field && !$seen_key) { echo ' ' . '<option value="' . htmlspecialchars($foreign_field) . '"' . ' selected="selected"' . '>' . $foreign_field . '</option>' . "\n"; } ?> </select> </td> <?php } // end if (internal relations) if (PMA_isForeignKeySupported($tbl_storage_engine)) { echo '<td>'; if (!empty($save_row[$i]['Key'])) { ?> <span class="formelement"> <select name="destination_foreign[<?php echo $myfield_md5; ?> ]" class="referenced_column_dropdown"> <?php if (isset($existrel_foreign[$myfield])) { // need to backquote to support a dot character inside // an element $foreign_field = PMA_backquote($existrel_foreign[$myfield]['foreign_db']) . '.' . PMA_backquote($existrel_foreign[$myfield]['foreign_table']) . '.' . PMA_backquote($existrel_foreign[$myfield]['foreign_field']); } else { $foreign_field = false;
/** * foreign key supported test * @dataProvider foreignkeySupportedDataProvider */ public function testForeignkeySupported($a, $e) { $this->assertEquals($e, PMA_isForeignKeySupported($a)); }
/** * * * @return array ??? */ function get_script_tabs() { $script_tabs = '<script type="text/javascript">' . "\n" . '// <![CDATA[' . "\n" . 'var j_tabs = new Array();' . "\n" . 'var h_tabs = new Array();' . "\n"; for ($i = 0, $cnt = count($GLOBALS['PMD']['TABLE_NAME']); $i < $cnt; $i++) { $script_tabs .= "j_tabs['" . $GLOBALS['PMD_URL']['TABLE_NAME'][$i] . "'] = '" . (PMA_isForeignKeySupported($GLOBALS['PMD']['TABLE_TYPE'][$i]) ? '1' : '0') . "';\n"; $script_tabs .= "h_tabs['" . $GLOBALS['PMD_URL']['TABLE_NAME'][$i] . "'] = 1;" . "\n"; } $script_tabs .= '// ]]>' . "\n" . '</script>' . "\n"; return $script_tabs; }