2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Display table relations for viewing and editing
6 * includes phpMyAdmin relations and InnoDB relations
8 * @todo fix name handling: currently names with dots (.) are not properly handled
9 * for internal relations (but foreign keys relations are correct)
10 * @todo foreign key constraints require both fields being of equal type and size
11 * @todo check foreign fields to be from same type and size, all other makes no sense
12 * @todo if above todos are fullfilled we can add all fields meet requirements
13 * in the select dropdown
18 * Gets some core libraries
20 require_once 'libraries/common.inc.php';
21 require_once 'libraries/index.lib.php';
22 require_once 'libraries/tbl_relation.lib.php';
24 $response = PMA_Response
::getInstance();
26 // Send table of column names to populate corresponding dropdowns depending
27 // on the current selection
28 if (isset($_REQUEST['getDropdownValues'])
29 && $_REQUEST['getDropdownValues'] === 'true'
31 PMA_sendHtmlForTableOrColumnDropdownList();
34 $header = $response->getHeader();
35 $scripts = $header->getScripts();
36 $scripts->addFile('tbl_relation.js');
37 $scripts->addFile('indexes.js');
40 * Sets globals from $_POST
43 'destination_foreign_db',
44 'destination_foreign_table',
45 'destination_foreign_column',
48 'foreign_key_fields_name',
53 foreach ($post_params as $one_post_param) {
54 if (isset($_POST[$one_post_param])) {
55 $GLOBALS[$one_post_param] = $_POST[$one_post_param];
60 * Gets tables informations
62 require_once 'libraries/tbl_info.inc.php';
64 $options_array = array(
65 'CASCADE' => 'CASCADE',
66 'SET_NULL' => 'SET NULL',
67 'NO_ACTION' => 'NO ACTION',
68 'RESTRICT' => 'RESTRICT',
72 * Gets the relation settings
74 $cfgRelation = PMA_getRelationsParam();
79 if ($cfgRelation['relwork']) {
80 $existrel = PMA_getForeigners($db, $table, '', 'internal');
82 if (PMA_Util
::isForeignKeySupported($tbl_storage_engine)) {
83 $existrel_foreign = PMA_getForeigners($db, $table, '', 'foreign');
85 if ($cfgRelation['displaywork']) {
86 $disp = PMA_getDisplayField($db, $table);
89 // will be used in the logic for internal relations and foreign keys:
90 $multi_edit_columns_name = isset($_REQUEST['fields_name'])
91 ?
$_REQUEST['fields_name']
95 // 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
96 if (isset($_POST['destination_db']) && $cfgRelation['relwork']) {
97 PMA_handleUpdatesForInternalRelations(
98 $_POST['destination_db'], $multi_edit_columns_name,
99 $_POST['destination_table'],
100 $_POST['destination_column'], $cfgRelation, $db, $table,
101 isset($existrel) ?
$existrel : null
103 } // end if (updates for internal relations)
107 $multi_edit_columns_name = isset($_REQUEST['foreign_key_fields_name'])
108 ?
$_REQUEST['foreign_key_fields_name']
111 // u p d a t e s f o r f o r e i g n k e y s
112 // (for now, one index name only; we keep the definitions if the
113 // foreign db is not the same)
114 if (isset($destination_foreign_db)) {
115 $html_output .= PMA_handleUpdatesForForeignKeys(
116 $destination_foreign_db,
117 $multi_edit_columns_name, $destination_foreign_table,
118 $destination_foreign_column, $options_array, $table,
119 isset($existrel_foreign) ?
$existrel_foreign['foreign_keys_data'] : null
121 } // end if isset($destination_foreign)
123 // U p d a t e s f o r d i s p l a y f i e l d
124 if ($cfgRelation['displaywork'] && isset($display_field)) {
125 PMA_handleUpdateForDisplayField(
126 $disp, $display_field, $db, $table, $cfgRelation
130 // If we did an update, refresh our data
131 if (isset($_POST['destination_db']) && $cfgRelation['relwork']) {
132 $existrel = PMA_getForeigners($db, $table, '', 'internal');
134 if (isset($destination_foreign_db)
135 && PMA_Util
::isForeignKeySupported($tbl_storage_engine)
137 $existrel_foreign = PMA_getForeigners($db, $table, '', 'foreign');
140 if ($cfgRelation['displaywork']) {
141 $disp = PMA_getDisplayField($db, $table);
148 // Now find out the columns of our $table
149 // need to use PMA_DatabaseInterface::QUERY_STORE with $GLOBALS['dbi']->numRows()
151 $columns = $GLOBALS['dbi']->getColumns($db, $table);
154 $html_output .= PMA_getHtmlForCommonForm(
155 $db, $table, $columns, $cfgRelation, $tbl_storage_engine,
156 isset($existrel) ?
$existrel : array(),
157 isset($existrel_foreign) ?
$existrel_foreign['foreign_keys_data'] : array(),
161 if (PMA_Util
::isForeignKeySupported($tbl_storage_engine)) {
162 $html_output .= PMA_getHtmlForDisplayIndexes();
164 // Render HTML output
165 PMA_Response
::getInstance()->addHTML($html_output);